|
Complex Boolean Expressions
It is possible to combine Boolean expressions with logical OR & AND operations, to form more complex Boolean expressions.
<bool-expr1> _AN_ <bool-expr2> Logical AND operation
<bool-expr1> && <bool-expr2> Logical AND operation
<bool-expr1> _OR_ <bool-expr2> Logical OR operation
<bool-expr1> || <bool-expr2> Logical OR operation
An AND Boolean expression gives a TRUE value if both of its operands are TRUE.
An OR Boolean expression gives a TRUE value if at least one of its operands is TRUE.
These logical operations did not exist in old GPP. However, in order to support developers who prefer the traditional operator style (_XX_), both styles have been implemented (traditional and C-like) and can be used.
Only Boolean expressions can be used as operands for these logical operations.
Example
X >= 10 && S1 = "abc"
(X > 0 && Y > 0) || (X < 0 && Y < 0)
The logical AND operator takes precedence over the logical OR operator (like multiply takes precedence over plus). Therefore, the second example could have been written without the parentheses. However, it is always advised to use parentheses in such expressions, in order to make them clearer and to avoid programming errors.
|