From: Robert Klemme Date: 2013-01-07T01:45:12+09:00 Subject: Re: Best practice for &&, ||, and, or On Sat, Jan 5, 2013 at 11:46 PM, Jan E. wrote: > And how is the low precendence of and/or "dangerous"? Isn't that exactly > what you want in an "if" statement? To have the logical operators > executed at the very end? Jan, I am not totally sure what you mean by this. In any case (&& or and) the left expression is evaluated before the operator and operator and boolean result of that left expression evaluation determine whether the right hand expression is evaluated _at all_. irb(main):001:0> def t(x)p x end => nil irb(main):002:0> t(false) and t(nil) false => false irb(main):003:0> t(false) && t(nil) false => false irb(main):004:0> t(1) or t(2) 1 => 1 irb(main):005:0> t(1) || t(2) 1 => 1 irb(main):007:0> t(1) and t(false) 1 false => false irb(main):008:0> t(1) && t(false) 1 false => false irb(main):009:0> t(false) or t(2) false 2 => 2 irb(main):010:0> t(false) || t(2) false 2 => 2 Precedence only indirectly affects execution order by means of grouping of expressions. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/