From: ara.t.howard@... Date: 2005-12-13T08:37:02+09:00 Subject: Re: Idiom wanted: do-while On Tue, 13 Dec 2005, 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? harp:~ > cat a.rb i = 0 ( p i i += 1 ) while i < 3 harp:~ > ruby a.rb 0 1 2 cheers. -a -- =============================================================================== | ara [dot] t [dot] howard [at] noaa [dot] gov | all happiness comes from the desire for others to be happy. all misery | comes from the desire for oneself to be happy. | -- bodhicaryavatara ===============================================================================