0

What is the difference between 3 == 3 and not("testing" == "testing" or "Ruby" == "Fun") and 3 == 3 && !("testing" == "testing" or "Ruby" == "Fun")?

The first one gives true and last one gives false. I thought that and is as same as && and not is same as !

Holger Just
  • 52,918
  • 14
  • 115
  • 123
VeronikaS
  • 151
  • 4
  • 1
    I cannot reproduce this. On my machine, both variants return `false`. What version of Ruby do you use? Or are there parts missing in your example like an assignment? – spickermann Mar 05 '20 at 16:20
  • Both code snippets should evaluate to `false` however `!` and `&&` have a higher precedence than `not` and `and`. So they're not exactly the same. – cremno Mar 05 '20 at 16:46
  • `&&` is a boolean operator whereas `and` is a control-flow operator. They are used in totally different contexts, e.g. `if this && that` vs. `do_this and return` – Stefan Mar 05 '20 at 17:10
  • 1
    Does this answer your question? [Difference between "and" and && in Ruby?](https://stackoverflow.com/questions/1426826/difference-between-and-and-in-ruby) – BM5k Mar 05 '20 at 17:42

0 Answers0