A relational expression consists of two or more expressions whose values are compared to determine whether the relationship stated by the relational operator is satisfied. The following are relational operators:

Operator | Relationship | |||
---|---|---|---|---|

.LT. | or | < | Less than | |

.LE. | or | <= | Less than or equal to | |

.EQ. | or | = = | Equal to | |

.NE. | or | /= | Not equal to | |

.GT. | or | > | Greater than | |

.GE. | or | >= | Greater than or equal to |

The result of the relational expression is .TRUE. if the relation specified by the operator is satisfied; the result is .FALSE. if the relation specified by the operator is not satisfied.

Relational operators are of equal precedence. Numeric operators and the character operator // have a higher precedence than relational operators.

In a numeric relational expression, the operands are numeric expressions. Consider the following example:

APPLE+PEACH > PEAR+ORANGE

This expression states that the sum of APPLE and PEACH is greater than the sum of PEAR and ORANGE. If this relationship is valid, the value of the expression is .TRUE.; if not, the value is .FALSE.

Operands of type complex can only be compared using the equal operator (= = or .EQ.) or the not equal operator (/= or .NE.). Complex entities are equal if their corresponding real and imaginary parts are both equal.

In a character relational expression, the operands are character expressions. In character relational expressions, less than (< or .LT.) means the character value precedes in the ASCII collating sequence, and greater than (> or .GT.) means the character value follows in the ASCII collating sequence. For example:

'AB'//'ZZZ' .LT. 'CCCCC'

This expression states that `'ABZZZ'`

is
less than `'CCCCC'`

. In this case, the
relation specified by the operator is satisfied, so the result is
.TRUE.

Character operands are compared one character at a time, in order, starting with the first character of each operand. If the two character operands are not the same length, the shorter one is padded on the right with blanks until the lengths are equal; for example:

'ABC' .EQ. 'ABC ' 'AB' .LT. 'C'

The first relational expression has the value .TRUE. even though
the lengths of the expressions are not equal, and the second has the
value .TRUE. even though `'AB'`

is longer
than `'C'`

.

A relational expression can compare two numeric expressions of different data types. In this case, the value of the expression with the lower-ranking data type is converted to the higher-ranking data type before the comparison is made.

For details on the ranking of data types, see Section 4.1.1.2.

Previous Page Next Page Table of Contents