Logical Operator Precedence

As with other operators, logical operators are evaluated according to a set precedence. Logical operators have a lower precedence than both arithmetic and comparison operators, meaning that these other types of operator will be evaluated first, after which any logical operations will be evaluated. In other words, the following expression:

8 / 4 < 2 * 10 & 14 / 2 = 3 + 4

Is evaluated as follows:

((8 / 4) < (2 * 10)) & ((14 / 2) = (3 + 4))

The arithmetic operators are evaluated first, giving us:

(2 < 20) & (7 = 7)

The comparison operators are next, which leaves us with:

True & True

Which, as we have learned in this session, evaluates to True.

If your expression contains one or more operators of equal precedence, they are evaluated as they appear from left to right.

 

<< Previous: Not ( ! )  | Next: Lesson Summary >>