From: John Feminella Date: 2011-05-08T11:48:13+09:00 Subject: Re: Help with while condition OR condition > Everyone should use 'and' and 'or' by default instead of && and ||. > Code reads better that way.  Only if you have a specific reason to, > should you use && or ||. It's not a good idea to make a blanket rule like that, imo. The "and" keyword is not really a substitute for "&&", since it has different precedence. It's best viewed as a control flow modifier (like "if" or "unless" when at the end of an expression), rather than a true logical operator. If you don't know that it's not quite the same, this can get you into big trouble by leading to subtle bugs. Consider this code, for instance: >> missiles_armed = true => true >> go_for_launch = false => false # Using && >> go_for_launch && missiles_armed ? :fire_ze_missiles : :abort_launch => :abort_launch # Looks good here. # Using "and" >> go_for_launch and missiles_armed ? :fire_ze_missiles : :abort_launch => false # Uh-oh! We didn't get the `:abort_launch` we were expecting... ~ jf -- John Feminella Principal Consultant, BitsBuilder LI: http://www.linkedin.com/in/johnxf SO: http://stackoverflow.com/users/75170/ On Sat, May 7, 2011 at 22:29, 7stud -- wrote: > Hi, > > A lot of beginners make the same mistake you did.   'Compound > conditionals' have to be written like separate conditionals and then > hooked together with an 'or' or 'and'.  For instance if you wanted to do > something only if a number were greater than 5 and less then 10, you > would do this: > > x > 5 > x < 10 > and > > if x > 5 and x < 10 >  #do something > end > > Everyone should use 'and' and 'or' by default instead of && and ||. > Code reads better that way.  Only if you have a specific reason to, > should you use && or ||. > > Good luck. > > -- > Posted via http://www.ruby-forum.com/. > >