That's the behavior I would expect it to have. Why wouldn't you do:
irb(main):001:0> i = 1
=> 1
irb(main):002:0> until i > 5
irb(main):003:1> p i
irb(main):004:1> i += 1
irb(main):005:1> end
1
2
3
4
5
instead?
···
----- Original Message ----
From: Martin Jansson <martialis@bigfoot.com>
To: ruby-talk ML <ruby-talk@ruby-lang.org>
Sent: Thursday, September 6, 2007 1:00:28 PM
Subject: Is this a bug or a feature?
irb(main):002:0> i=1
=> 1
irb(main):003:0> until (i+=1)>5
irb(main):004:1> p i
irb(main):005:1> end
2
3
4
5
=> nil
irb(main):006:0> RUBY_VERSION
=> "1.8.3"
The condition is evaluated before the first iteration.
At least it's consistent:
irb(main):005:0> i = 1
=> 1
irb(main):006:0> p i until (i+=1)>5
2
3
4
5
=> nil
I think it makes "until" less useful. Why would anyone want this?
--
Posted via http://www.ruby-forum.com/.
____________________________________________________________________________________
Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7