Logical expressions can only have the value
.FALSE. A logical
expression can be formed by comparing arithmetic expressions using the following
A D V E R T I S E M E N T
.LT. means less than (<)
.LE. less than or equal (<=)
.GT. greater than (>)
.GE. greater than or equal (>=)
.EQ. equal (=)
.NE. not equal (/=)
So you cannot use symbols like < or = for
comparisons in Fortran 77.
For example: (x.eq.y) is valid while (x=y) is not valid
in Fortran 77.<or = for comparison in
Fortran 77, but you have to use the correct two-letter abbreviation enclosed by
dots! (Such symbols are allowed in Fortran 90, though.) >
Logical expressions can be combined by the logical
operators .AND. .OR.
.NOT. which have the obvious meaning.
Logical variables and assignment
Truth values can
be stored in logical variables. The assignment is analogous to the
arithmetic assignment. Example:
logical a, b
a = .TRUE.
b = a .AND. 3 .LT. 5/2
The order of precedence is
important, as the last example shows. The rule is that arithmetic expressions
are evaluated first, then relational operators, and finally logical operators.
Hence b will be assigned
.FALSE. in the example above.
Logical variables are seldom used in Fortran. But logical
expressions are frequently used in conditional statements like the