From: Andrew Johnson Date: 2004-09-19T02:09:44+09:00 Subject: Re: [Nuby Question] Return value of while loop. On Sun, 19 Sep 2004 01:25:07 +0900, Markus wrote: > On Sat, 2004-09-18 at 08:36, ts wrote: >> >>>>> "O" == Olivier D writes: >> >> O> i <<= 1 while defined?(i) ? (i < 100) : (i = 1) >> >> i <<= 1 while i.nil?? (i = 1):(i < 100) > > i <<= 1 while (i = i||1) < 100 i *= 2 while (i = i||1) < 100 :-) However, if I read the OP correctly, the interest wasn't the shortest expression that sets i to 128 via doubling --- the interest was in the shortest expression that "returned" the value of i thusly set (sans semi-colons). The original example of what the OP was after (in irb): :~$ irb irb(main):001:0> i = 1 => 1 irb(main):002:0> loop do irb(main):003:1* i *= 2 irb(main):004:1> break i if i > 100 irb(main):005:1> end => 128 My first thought used the ability (for good or evil) to combine if/while modifiers: :~$ irb irb(main):001:0> i = 1 => 1 irb(main):002:0> break i if i > 100 while i = i || 1 and i *= 2 => 128 But a little rearranging results in a one liner: :~$ irb irb(main):001:0> (i *= 2) > 100 and break i while i = i || 1 => 128 regards, andrew -- Andrew L. Johnson http://www.siaris.net/ They're not soaking, they're rusting! -- my wife (on my dishwashing habits)