Logical Operators
Logical operators are used to combine or modify conditions
A logical operator is a symbol used to perform logical operators. They combine or invert TRUE and FALSE conditions.
AND, OR and NOT are the three common operators.
AND
AND Operator
The AND operator checks if both conditions are true. The result is true only if both conditions are true.
AND Operator purpose
The AND operator is used to check if two conditions are both true.
Example
“The password must contain a number AND a special character to be valid.”
| Condition A | Condition B | A AND B |
|---|---|---|
| True | True | True |
| True | False | False |
| False | True | False |
| False | False | False |
OR
OR Operator
The OR operator checks if either input is true. If any of the the inputs are true then the output is also true.
OR Operator purpose
The OR operator is used to ensure at least one input is true.
Example
“The user can pick either red OR blue, if so they can proceed.”
| Condition A | Condition B | A AND B |
|---|---|---|
| True | True | True |
| True | False | True |
| False | True | True |
| False | False | False |
NOT
NOT Operator
The NOT operator reverses a condition.
- If a condition is true, NOT makes it false.
- If a condition is false, NOT makes it true.
NOT operator purpose
The NOT operator is used to reverse a condition.
Example
“Show all results NOT containing the word ‘Glasgow’.”
| Condition A | NOT A |
|---|---|
| True | False |
| False | True |