Logical Expressions

A logical expression is a sequence of one or more logical operands and logical operators. It evaluates to a single logical value. The operators can be any of the following.

Table 3-4 Logical Operators

Logical disjunction (inclusive OR )

Logical exclusive OR

The period delimiters are necessary.

Two logical operators cannot appear consecutively, unless the second one is the .NOT. operator.

Logical operators are evaluated according to the following precedence:

Table 3-5 Logical Operator Precedence

If the logical operators are of equal precedence, they are evaluated left to right.

If the logical operators appear along with the various other operators in a logical expression, the precedence is as follows.

Table 3-6 Operator Precedence

The following table shows the meanings of simple expressions:

Table 3-7 Logical Expressions and Their Meanings

Both X and Y are true.

Either X or Y , or both, are true.

X and Y are not both true and not both false.

Either X or Y is true, but not both.

X and Y are both true or both false.

This is the syntax for the assignment of the value of a logical expression to a logical variable:

A logical expression, an integer between -128 and 127, or a single character constant

A logical variable, array element, or record field

Execution of a logical assignment statement causes evaluation of the logical expression e and assignment of the resulting value to v . If e is a logical expression, rather than an integer between -128 and 127, or a single character constant, then e must have a value of either true or false.

Logical expressions of any size can be assigned to logical variables of any size.

Assigning numerics to logicals is allowed. (All non-zero values are treated as .TRUE., and zero is .FALSE.) This practice is nonstandard, however, and is not portable. @

Example: A logical assignment:

LOGICAL B1*1, B2*1 LOGICAL L3, L4 B2 = B1 B1 = L3 L4 = .TRUE.