From: John Sikora Date: 2010-08-18T13:06:39+09:00 Subject: Re: Strange behavior of or condition in loop AppleII717 wrote: > I don't understand why ruby's "or" acts differently in a loop. > > This is some code I pulled out of a rails model, expanded the > assignments and simulated in IRB (1.8.7 and 1.9.2rc) > > #simple boolean assignments > #Why does this work > > dirty = false > found = true > dirty = dirty or found > puts dirty.to_s => true > A lot of great info in here but I was left with a question: Why did it work outside the loop (in the example given above) but not inside the loop? So I tried the inside the loop code both in irb and from a file (using 1.9.1) and I got false, not true. See the irb session below. It makes me feel better that it works the same way in both instances. AppleII717, are you sure you got 'true' in the code above? Note that there is a 'true' output, but I think that it is because (dirty = dirty) or found returns true, but dirty is false. irb(main):001:0> dirty = false => false irb(main):002:0> found = true => true irb(main):003:0> dirty = dirty or found => true irb(main):004:0> dirty => false irb(main):005:0> dirty.to_s => "false" irb(main):006:0> js -- Posted via http://www.ruby-forum.com/.