Comparison Operator Precedence
As with arithmetic operators, comparison operators are evaluated according to a set precedence. Equality operators (= and <>) have a slightly lower precedence than those involving greater than or less than evaluation (>, <, >= and <=), which means that the following expression:
Mass1Heavier = Mass1Weight > Mass2Weight
Is the same as:
Mass1Heavier = ( Mass1Weight > Mass2Weight )
Whenever you have two or more operators with the same precedence in an expression, each pairing is evaluated in the order they appear from left to right. For that reason, the following expression equates to False:
9 < 10 > 8
You might wonder why the above statement is False, but remember that the first pairing is evaluated before the second, so it may help to think of it like this:
( 9 < 10 ) > 8
9 < 10 is True, so the value of that sub-expression is 1. Since 1 > 8 is False, the overall value of the expression is also False.
<< Previous: Comparing Strings | Next: Lesson Summary >>