James Gray
12/12/2005 10:43:00 PM
On Dec 12, 2005, at 4:34 PM, Adam Shelly wrote:
> So I was working on the quiz solution, and
> I had some code like this:
>
> b = simulate board,m
> while another_turn?(b,m)
> b = simulate b,m
> end
>
>
> If I was doing this in C, I'd use a do-while loop instead, to avoid
> repeating the line outside the loop:
>
> b = board;
> do {
> b = simulate(b.m);
> }
> while ( another_turnta(b,m));
>
> What's the do-while idiom in ruby?
> I ended up with this, but it needs an extra flag variable:
>
> b,taketurn = board,true
> while taketurn
> b = simulate b,m
> taketurn = another_turn?(b,m)
> end
>
> Is there a ruby idiom for do-while?
I favor:
loop do
# ... some action ...
break unless ...
end
Hope that helps.
James Edward Gray II