Why should we use '&&' and '||' operator while they works same as 'and' and 'or'? Someone please explain | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Why should we use '&&' and '||' operator while they works same as 'and' and 'or'? Someone please explain

14th Dec 2015, 2:18 AM
The Most Mysterious
The Most Mysterious - avatar
11 Answers
+ 4
&& has higher precedence than and. example: if $ a is true and $ b is false then for $ c= $ a && $ b c will be false as && has greater precedence than =. but for $ c= $ a and $ b c will be true as and has lower precedence than =.
1st Jul 2016, 9:27 AM
Midhun Mathew
+ 1
May be they are options to each other. ...v don't have to use them compulsarily
14th Dec 2015, 6:35 PM
Anushree Bobhate
Anushree Bobhate - avatar
+ 1
There is a very subtle difference between & and &&, even though the results will be same for a given expression. For eg. if the exp is a&&b, the compiler will just check for the left side; if the left side is false it declares the exp false without checking for the other side. Similarly for a||b, if the compiler finds a to be true it declares the whole exp true without bothering about other. On the other hand & and | always force the compiler to check both sides of the operator no matter what the situation. If you want to go even more technically, & and | are used for manipulating bits (outside context and scope) , and in almost all conditional statements && and || are generally used.
5th Aug 2016, 11:32 AM
Sumitabha Banerjee
Sumitabha Banerjee - avatar
0
both AND and && can use for that symbolic representation is that
15th Dec 2015, 4:41 AM
Maneesh M
Maneesh M - avatar
0
&& same as AND, || same as OR
27th Dec 2015, 12:54 PM
Agung Kharisma Sukarno
Agung Kharisma Sukarno - avatar
0
for convenient purpose. ..you can use any one...depends on your choice.
16th Jan 2016, 4:09 PM
Mritunjay Chourasia
Mritunjay Chourasia - avatar
0
Just an alternative way I believe.
29th Jan 2016, 5:41 PM
Magician
Magician - avatar
0
If you're used to programming you'd use '&&' and '||' as they're common among other languages, but 'and' and 'or' would make more sense for someone who's only getting started or maybe only interested in learning php alone ;)
31st Jan 2016, 11:37 AM
Omar Einea
Omar Einea - avatar
14th Feb 2016, 3:33 AM
Miguel Angel Sánchez Martínez
Miguel Angel Sánchez Martínez - avatar
0
"||" and "&&" have a greater precedence than "or" and "and"
14th Feb 2016, 1:30 PM
Mohamed Abd alaziz
Mohamed Abd alaziz - avatar