FORTRAN 77 Language Reference

# 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

Operator

Standard Name

.AND.

.OR.

.NEQV.

.XOR.

.EQV.

.NOT.

Logical conjunction

Logical disjunction (inclusive OR)

Logical nonequivalence

Logical exclusive OR

Logical equivalence

Logical negation

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

Operator

Precedence

.NOT.

.AND.

.OR.

.NEQV.,.XOR., .EQV.

Highest

Lowest

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

Operator

Precedence

Arithmetic

Character

Relational

Logical

Highest

Lowest

The following table shows the meanings of simple expressions:

Table 3-7 Logical Expressions and Their Meanings

Expression

Meaning

X .AND. Y

X .OR. Y

X .NEQV. Y

X .XOR. Y

X .EQV. Y

.NOT. X

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.

Logical negation.

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

v = e

e

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

v

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. ```