Relational Operators

The action of the relational operators GTR, >, GEQ, >=, LSS, <, LEQ, <=, EQL, =, NEQ, and ^= depends on the kinds of items being compared. For more information, refer to Arithmetic Relation, Complex Relation, String Relation, Pointer Relation, and String Expression Relation later in this section.

Precedence in Boolean Expressions

The components of Boolean expressions are evaluated in the following order:

  1. All arithmetic, complex, pointer, and string expressions are evaluated.

  2. All relations, table memberships, and assignments are evaluated.

  3. Logical operators are then applied.

The order of precedence of the logical operators is as follows:

  1. NOT (highest precedence)

  2. AND/ CAND (both have same precedence)

  3. OR/ COR (both have same precedence)

  4. IMP

  5. EQV

Operators with the same precedence are applied in their order of appearance in an expression, from left to right.

The precedence of the assignment operator (:=) is as follows:

  1. A primary to the right of an assignment operator is evaluated before the assignment.

  2. The assignment is done before the evaluation of an expression involving the variable that is the target of the assignment.

Parentheses can be used in normal mathematical fashion to override the defined order of precedence. An expression in parentheses is evaluated by itself, and the resulting value is subsequently combined with the other elements of the expression. In the following expression, for example, the OR is performed before the AND operator because of the parentheses:

X AND (Y OR Z)

In the following expression the AND is performed before the OR:

X AND Y OR Z

For information on the order of evaluation of subscripts, see “Arithmetic Update Assignment” in Statements.