Logical Operators
Logical operators are used in conditional statements to test whether one or more expressions are TRUE or FALSE.
The AND Operator
AND is used to test whether two expressions both evaluate to TRUE, as shown below:
Condition1 AND Condition2
This statement equates to TRUE only if both Condition1 AND Condition2 are TRUE. This can be illustrated using the following truth table:
| Truth Table for AND Operator | ||
| Condition1 | Condition2 | Condition1 AND Condition2 |
| FALSE | FALSE | FALSE |
| FALSE | TRUE | FALSE |
| TRUE | FALSE | FALSE |
| TRUE | TRUE | TRUE |
The OR Operator
OR is used to test whether at least one of two expressions evaluates to TRUE, as shown below:
Condition1 OR Condition2
This statement equates to TRUE if either Condition1 or Condition2 (or both) is TRUE. This can be illustrated using the following truth table:
| Truth Table for OR Operator | ||
| Condition1 | Condition2 | Condition1 OR Condition2 |
| FALSE | FALSE | FALSE |
| FALSE | TRUE | TRUE |
| TRUE | FALSE | TRUE |
| TRUE | TRUE | TRUE |