It’s
possible to construct logical expressions with more than two Boolean operators
just as we can have an arithmetic expressions with
multiple operators. In both cases, we
need to worry about the order in which operators are evaluated (precedence
rules). For Boolean operators,
negation (!) has highest precedence, followed by the logical and
(&&), and finally the logical or (||). Consider the following expression with
three relational statements and their truth values below: stmt1 ||
stmt2 && stmt3
T F F The
expression evaluates to true since && is
evaluated first (resulting in false), and then
the || operator (Beware: evaluating from left two right without taking operator precedence into account
would have yielded false). When in doubt about
precedence, it’s a good idea to use parentheses. |