A logical expression can have any of the following forms:
and the logical operator can be any of the following:
.AND. | logical and |
.OR. | logical inclusive or |
.EQV. | logical equivalence |
.NEQV. | logical non-equivalence (i.e. exclusive or). |
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.
x | y | x .AND. y | x .OR. y | x .EQV. y | x .NEQV. y |
false | false | false | false | true | false |
true | false | false | true | false | true |
false | true | false | true | false | true |
true | true | true | true | true | false |
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:
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.