Suppose you had the following declaration:
var p, q : boolean
These boolean operators can be summarized in the following truth table:
Each of these operators has a different precedence in the order of operations. The operator with the highest precedence of the three is not. The next highest is and. The lowest is or. Here is a table that outlines the order of operations for all the operators we've seen so far. Operators on the same line have the same precedence.
** * / div mod + - < <= = not= > >= not and or |
Here are some examples using boolean operators:
not false and true = true and true = true
5 < -10 or 'M' >= 'M' = false or true = true
not (5 + 10 = 15 and 7 not= 8) = not (15 = 15 and true) = not (true and true) = not true = false
false or true and false = false or false = false
Take note of the last example. Remember that ands are executed before ors. If you do the or first you will get the wrong answer. Here is a small program using two of the new operators:
|
|