Difference between, 'and' , 'or' | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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'

3rd Mar 2017, 10:20 PM
Jan Andersson
Jan Andersson - avatar
7 Answers
+ 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
3rd Mar 2017, 10:26 PM
Victor Almendro
Victor Almendro - avatar
+ 2
They're self-explainatory, honestly. And, if you've ever written an if statement, you've used a logic operator.
3rd Mar 2017, 10:25 PM
Keto Z
Keto Z - avatar
+ 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.
3rd Mar 2017, 10:33 PM
Keto Z
Keto Z - avatar
+ 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" ?
9th Mar 2017, 6:34 AM
Ahmed Pathan
Ahmed Pathan - avatar
0
Boolean statements by definition aren't logic operators
3rd Mar 2017, 10:28 PM
Jan Andersson
Jan Andersson - avatar
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.
3rd Mar 2017, 10:58 PM
Jan Andersson
Jan Andersson - avatar
0
AND - Do you want coffe and a chocolate cake? OR - Do you want coffe or a chocolate cake?
18th Apr 2017, 4:53 PM
Rafael Figueroa
Rafael Figueroa - avatar