Boolean logic
Boolean logic takes two statements or expressions and applies a logical operator to generate a
Boolean value that can be either true or false. To return the result, operators like AND, OR, NOT,
etc. are used.
There are three basic Boolean operators, AND, OR, and NOT
1. AND operator (&&)
2. OR operator (| |)
3. NOT operator (!)
1. AND Operator (&&)
The symbol used for AND operator is (&&). It is used to evaluate two conditions. It produces true
result if both conditions are true. It produces false result if any one condition is false.
Example
Suppose we have two variables A = 100 and B = 50. The compound condition (A>10) && (B>10)
is true. It contains two conditions and both are true. So the whole compound condition is also
true.
The compound condition (A>50) && (B>50) is false. It contains two conditions. One condition
(A > 50) is true and second condition (B>50) is false. So the whole compound condition is false.
Notes by: Mariam Tariq
2. OR Operator ( | | )
The symbol used for OR operator is ( | | ). It is used to evaluate two conditions. It produces true
result if either condition is true. It gives false result if both conditions are false.
Example
Suppose we have two variables A=100 and B=50. The compound condition (A>50) || (B>50) is
true. It contains two conditions and one condition (A>50) is true. So the whole compound
condition is also true. The compound condition (A>500) || (B>500) is false because both
conditions are false.
3. NOT Operator (!)
The symbol used for NOT operators (!). It is used to reverse the result of a condition. It gives true
result if the condition is false. It gives false result if the condition is true.
Example
Suppose we have two variables A = 100 and B = 50. The condition !(A==B) is true. The result of
(A==B) is false but NOT operator converts it into true. The condition !(A>B) is false. The
condition (A > B) is true but NOT operator converts it into false.
Notes by: Mariam Tariq