From: Hal Fulton Date: 2003-09-04T00:12:46+09:00 Subject: Re: Possible to make compound if statements... nobu.nokada@softhome.net wrote: >>Also 'and' and 'or' have "extremely low precedence" (according to Ruby in a >>Nutshell) so constructs using them _may_ behave differently than those >>using && and || and my need parentheses to clear up ambiguities. I don't >>have any good examples, but I'm sure someone does. > > > foo = false || bar = true # foo = true, bar = true > foo = false or bar = true # foo = false, bar = true > > The former is equivalent to > > foo = (false or bar = true) > > and the latter is > > (foo = false) || (bar = true) In case a newbie gets confused: He does mean = here, not ==. An assignment returns the value assigned. > Also note that 'and' and 'or' have same precedence. > > (foo or bar and bas) means ((foo || bar) && bas) > but > (foo || bar && bas) is (foo || (bar && bas)) This confuses me. So && is higher precedence than || but 'and' is not higher than 'or'. In short: true or true and false # false true || true && false # true For more reasons than readability, I think these should certainly not be mixed: if a and b || c or d && e || f and g... :) Hal