previous contents index next
(..Expressions..) Contents Index (Assignments (Var.)..)

2.10.4 Boolean Expressions (BoolExpression)

BoolExpression - Syntax:

Syntax: BoolExpression

Analogous to the other expression classes, roughly speaking, all objects that represent boolean values belong to the class of boolean expressions. To be at bit more sophisticated, we distinguish again between elementary and compounded expressions. To the first group belong

We have already had a look at them.

Furthermore elementary boolean expressions are also obtained as results of comparisons between expressions of other types. Although they have been introduced earlier, their full syntax is given here again:

In case of strings and integers, RelOp may be any relational operator ==, !=, <, <=, >, or >= whatever.
Since it makes no sense to apply < or > to cell expressions, the only remaining cases here are
 

Going over to compounded boolean expressions, we observe that a parenthezised boolean expression is again a boolean expression:

( BoolExpression )

Like in the context of integer expressions, the parentheses do the same here. Their high evaluation prioritiy causes the expression within to be evaluated first.


But what should parentheses be useful for without a chance to gain more complex boolean expressions connecting easy ones? Therefore, we have the logical operators && (AND), || (OR), and ! (NOT) at our disposal:

BoolExpression1 && BoolExpression2
BoolExpression1 || BoolExpression2


!BoolExpression


Remark:
If (boolean) results of comparisons are connected by && or ||, parentheses are not needed to make clear which are the boolean expressions. The evaluation priority of relational operators is higher than the one of AND and OR.
The situation changes as soon as the logical negation ! is involved: its priority is higher than the members of both RelOp and LogOp. Especially if the result of a comparison should be denied, the comparison must be collected in parentheses.
Observe furthermore that the priority of && is higher than of ||. (In case of remaining doubts you may consult the operator table.)
Some examples of boolean expressions can be found in example 14.


previous contents index next
(..Expressions..) Contents Index (Assignments (Var.)..)