0
Difference between, 'and' , 'or'
I have being programming for a long time but never really used logic operators, I really don't understand the difference between 'and' and 'or'
7 Respostas
+ 3
and = both statments need to be true so the code cotinues
or = any of both statments need to be true so the code continues
if(1<2 && 2<3){} code returns true
if(1<2 && 2>3){} code returns false
if(1<2 || 2<3){} code returns true
if(1<2 || 2>3){} code returns true
if(1>2 || 2>3){} code returna false
+ 2
They're self-explainatory, honestly. And, if you've ever written an if statement, you've used a logic operator.
+ 2
I'm going off of you saying that you've been programming for a long time. All programmers use if statements, and so, I figured you would have at leased used "not" (!) before. A programmer that doesn't ever use if statements is unheard of.
+ 1
AND and OR operators are used when you need to check two or more conditions in the same statement. consider the following pseudo-code :
check if oranges are apples AND sky is blue
print(this is true)
else print(false)
now in the above case, oranges are NOT apples but the sky is blue. So according to the AND truth table, AND returns true only if both(or all) conditions in the statement are true.Thus the above case will print FALSE.
But if we consider the same example with OR
check if oranges are apples OR sky is blue
print(this is true)
else print(false)
It will print TRUE as OR returns true even if one(or more) conditions of the statement are true.
Hope this clears your doubts.
And how many years are we talking about, when you say "I have been programming for a long time" ?
0
Boolean statements by definition aren't logic operators
0
I have used it before I just got confused with logic gates operators when learning MySQL that's why I asked this question in the first place.
0
AND - Do you want coffe and a chocolate cake?
OR - Do you want coffe or a chocolate cake?