next up previous contents index
Next: Guidelines Up: Logical Expressions Previous: Logical Expressions

Rules

A logical expression can have any of the following forms:

Where: logical-term can be any of the following:

and the logical operator can be any of the following:  

tabular892

Note that the rules of logical expressions only allow two successive operators to occur if the second of them is the unary operator .NOT. which negates the value of its operand. The effects of the four binary logical operators are shown in the table below for the four possible combinations of operands, x and y.

tabular901

Note that a logical expression can have operands which are complete relational expressions, and these can in turn contain arithmetic expressions. The complete order of precedence of the operators in a general expression is as follows:

  1. arithmetical operators (in the order defined in section 6.1 above).
  2. relational operators
  3. .NOT.
  4. .AND.
  5. .OR.
  6. .EQV. and .NEQV.

If the operators .EQV. and .NEQV. are used at the same level in an expression they are evaluated from left to right.

These rules reduce the need for parentheses in logical expressions, thus:
(X .GT. A) .OR. (Y .GT. B)
would have exactly the same meaning if all the parentheses had been omitted.

A Fortran system is not required to evaluate every term in a logical expression completely if its value can be determined more simply. In the above example, if X had been greater than A then it would not be necessary to compare Y and B for the expression would have been true in either case. This improves efficiency but means that functions with side-effects should not be used.



Mario Storti
Wed Nov 4 19:32:56 ART 1998