On Jul 30, 2009, at 11:15 AM, Lloyd Linklater wrote:

> I have the answer.  fyi, it is that
>
> doSomething until condition
>
> does not work at all like
>
> begin doSomething end until condition
>
> In the first case, the condition is checked BEFORE the doSomething is
> run.  In the second case, the condition is checked AFTER the  
> doSomething
> is run.  I am not sure just why this is or how I could have figured it
> out intuitively.  It seems to me that it would be better to have
> something like this (to mimic pascal)
>
> doSomething while condition #check condition before
>
> doSomething until condition #check condition after
>
> Thanks for all your input everyone!  I finally got there.  :)
> -- 
> Posted via http://www.ruby-forum.com/.

irb> i = Time.now.to_f + 0.001; begin print('.') end until  
Time.now.to_f > i
.....................................................................................................= 
 > nil
irb> i = Time.now.to_f - 0.001; begin print('.') end until  
Time.now.to_f > i
.=> nil
irb> i = Time.now.to_f - 0.001;       print('.')     until  
Time.now.to_f > i
=> nil
irb> i = Time.now.to_f - 0.001;       print('.')     while  
Time.now.to_f < i
=> nil
irb> i = Time.now.to_f - 0.001; begin print('.') end while  
Time.now.to_f < i
.=> nil
irb> i = Time.now.to_f + 0.001;       print('.')     while  
Time.now.to_f < i
......................................................................................................................................= 
 > nil

Well, I didn't believe you until I tried it myself. Seems that both  
until and while behave similarly when applied to a block rather than a  
simple expression.

$ ruby -v
ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]

I get the same results with ruby -e "..." as I do with irb so it's not  
just an irb oddity.

-Rob

Rob Biedenharn		http://agileconsultingllc.com
Rob / AgileConsultingLLC.com