Logical or Boolean operators are often used when you need to evaluate multiple relational expressions to return a single value. For example, in a Selection block, an action may depend on the evaluation of more than one expression.
The three primative (basic) logical operators are AND, OR, and NOT. All programming languages allow more complex logical operations, and many will have specific operators built in to achieve this.
AND evaluates to True when all of the relational expressions evaluate to True.
OR evaluates to True when either or both of the relational expressions evaluate to True.
NOT evaluates to True when the relational expression evaluates to False.
To ensure that the relational expressions are evaluated in the correct order, you should use parentheses (brackets) to make the order clear. Relational expressions in parentheses will be evaluated first.
If there are no parentheses in a relational expression, then the default order of operations or order of precedence is applied:
The NOT operator has the highest precedence, so it is applied first
Then, the AND operator is applied
Then, the OR operator is applied
It is also possible to use the logic of NAND and NOR in Boolean expressions. However, many programming languages do not provide these as single logical operators. You can create the appropriate logic by combining two separate operators, NOT AND and NOT OR.
The logical XOR (exclusive OR) operator can be used to form a Boolean expression that will evaluate to True when only one relational expression is True. If both relational expressions are False or both are True, then the output is False.