Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #4130

Re: Help with while condition OR condition

From Brian Candler <b.candler@pobox.com>
Newsgroups comp.lang.ruby
Subject Re: Help with while condition OR condition
Date 2011-05-08 09:45 -0500
Organization Service de news de lacave.net
Message-ID <f5103a314176f2296484e3603dc779f6@ruby-forum.com> (permalink)
References <fe6567119d5fbe466a7c6d2885d4718a@ruby-forum.com> <21f342aaa24993413edad3ec1e101650@ruby-forum.com>

Show all headers | View raw


7stud -- wrote in post #997311:
> In ruby, everyone should use 'and' and 'or' by default instead of && and
> ||.

I would advise exactly the opposite: there are many traps for the unwary 
if you use 'and' and 'or'. Two prime examples:

>> val = 10
=> 10
>> ok = val < 3 or val > 5
=> true
>> ok
=> false

>> a = true
=> true
>> b = not a
SyntaxError: compile error
(irb):7: syntax error, unexpected kNOT

Use '||' and '!' respectively and you won't have a problem.

-- 
Posted via http://www.ruby-forum.com/.

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Help with while condition OR condition "Bill W." <sirwillard42@gmail.com> - 2011-05-07 17:37 -0500
  Re: Help with while condition OR condition Steve Klabnik <steve@steveklabnik.com> - 2011-05-07 17:52 -0500
  Re: Help with while condition OR condition Christopher Dicely <cmdicely@gmail.com> - 2011-05-07 17:53 -0500
  Re: Help with while condition OR condition John Feminella <johnf@bitsbuilder.com> - 2011-05-07 17:54 -0500
    Re: Help with while condition OR condition John Feminella <johnf@bitsbuilder.com> - 2011-05-07 17:55 -0500
  Re: Help with while condition OR condition Joel VanderWerf <joelvanderwerf@gmail.com> - 2011-05-07 17:56 -0500
  Re: Help with while condition OR condition Hashmal <jeremypinat@gmail.com> - 2011-05-08 01:06 +0200
  Re: Help with while condition OR condition "Bill W." <sirwillard42@gmail.com> - 2011-05-07 18:38 -0500
  Re: Help with while condition OR condition Josh Cheek <josh.cheek@gmail.com> - 2011-05-07 20:15 -0500
  Re: Help with while condition OR condition 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-07 21:29 -0500
    Re: Help with while condition OR condition John Feminella <johnf@bitsbuilder.com> - 2011-05-07 21:48 -0500
    Re: Help with while condition OR condition Brian Candler <b.candler@pobox.com> - 2011-05-08 09:45 -0500
      Re: Help with while condition OR condition 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-09 15:11 -0500
        Re: Help with while condition OR condition Phillip Gawlowski <cmdjackryan@googlemail.com> - 2011-05-09 16:42 -0500

csiph-web