0

Possible Duplicates:
PHP - and / or keywords
Ruby: difference between || and 'or'

What is the difference between this:

a=20
b=30
if (a > 10 && b > 10)
    puts a
end

and this:

if (a > 10 and b > 10)
puts a
end

and also explain difference between "||" and "or"

Community
  • 1
  • 1
Mr. Black
  • 11,692
  • 13
  • 60
  • 85
  • 3
    Why did you tag this as PHP? I removed the PHP tag and changed the Rails tag to just Ruby, since the code examples are Ruby (or invalid PHP :P). Many answers here are talking about PHP however. I'm sorry for the confusion. (It seems the answer is the same in both languages, though.) – R. Martinho Fernandes Apr 04 '11 at 11:14
  • Since you tagged `[php]` and all the current answers are linking to the PHP documentation, I've marked this as an exact duplicate of [PHP - and / or keywords](http://stackoverflow.com/questions/4502092/php-and-or-keywords), where you will find the exact same answers. – Andy E Apr 04 '11 at 11:15
  • I have found the answer for my question. I have posted the answer below. Please review that. thanks to all. – Mr. Black Apr 04 '11 at 12:06

5 Answers5

7

The answer relates to the PHP tag that has been assigned to this question, but has been deleted afterwards

They are the same with one small difference. The and and or operator have a lower precedence compared to && and ||.

Take this example from the manual:

// The result of the expression (true && false) is assigned to $g
// Acts like: ($g = (true && false))
$g = true && false;

// The constant true is assigned to $h and then false is ignored
// Acts like: (($h = true) and false)
$h = true and false;
user229044
  • 232,980
  • 40
  • 330
  • 338
Stefan Gehrig
  • 82,642
  • 24
  • 155
  • 189
1

You can read about operators in PHP's documentation.

fabrik
  • 14,094
  • 8
  • 55
  • 71
1

Only the difference in precedence

Shakti Singh
  • 84,385
  • 21
  • 134
  • 153
1

As you can see from the precedence table for Ruby, the difference is also precedence, as it is in PHP: and and or have lower precedence than && and ||.

But there is a slight difference from PHP: in Ruby, and and or have the same precedence.

R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
0

I got the answer. Please go and read it. this is what i'm expect it.

http://avdi.org/devblog/2010/08/02/using-and-and-or-in-ruby/

Thanks all of your efforts

Mr. Black
  • 11,692
  • 13
  • 60
  • 85