From: dblack@... Date: 2007-09-07T04:57:52+09:00 Subject: Re: Is this a bug or a feature? Hi -- On Fri, 7 Sep 2007, Mark Volkmann wrote: > > On Sep 6, 2007, at 2:16 PM, Wilson Bilkovich wrote: > >> On 9/6/07, Martin Jansson wrote: >>> 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? >> >> What other behavior would you want, and why? >> Here are some specs for the current behavior of 'until'. They may help. >> http://rubyurl.com/12y > > I think what Martin wants is a bottom-tested loop, but I don't believe > Ruby has that. until is a top-tested loop just like while. The only way I > know to get bottom-tested behavior is this. > > loop do > # some code goes here > break if condition > end You can do: begin # do stuff end until condition David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)