Comparison operators

REXX comparison operators compare two terms and return the value 1 if the result of the comparison is true, or 0 otherwise. Comparison operators can compare numbers or character strings. The most commonly used comparison operators are:

Operator
Meaning
=
Equal
¬=, \=
Not equal
<
Less than
¬<, \<
Not less than
>
Greater than
¬>, \>
Not greater than
<=
Less than or equal to
>=
Greater than or equal to
><
Greater than or less than (same as not equal)
<>
Less than or greater than (same as not equal)

The “not” character (¬), is synonymous with the backslash (\). You can use the two characters interchangeably.

When comparing terms using these comparison operators, if both terms in the expression are numeric, REXX performs a numeric comparison. Otherwise, both terms are treated as character strings and REXX performs character comparison. (A number in REXX is a string that contains one or more decimal digits, an optional decimal point, and an optional leading sign character. The string can contain one or more leading or trailing blanks, and the sign character can be separated from the digits by one or more blanks.)

In a character comparison, leading and trailing blanks are ignored, and the shorter string is padded with blanks on the right. Character comparisons are case-sensitive. Therefore, you should delimit character strings with quotation marks to prevent lowercase characters being translated to upper case. For example, if the field #4 contains the value MixedCase both the following comparison operations would be true:

#4 = 'MixedCase'
#4 = '    MixedCase     '

but the following comparison operation would not be true:

#4 = MixedCase

In numeric comparisons, the comparison is effected by subtracting the two numbers (calculating the difference) and then comparing the result with 0. For example, the comparison operation:

#6 = 10

is identical to the operation:

(#6 - 10) = 0

In addition to these comparison operators, REXX provides a number of “strict” comparison operators that are mainly intended for use when comparing character strings. The strict comparison operators all have one of the characters defining the operator doubled, such as == (strictly equal).

The strict comparison operators are:

Operator
Meaning
==
Strictly equal
¬==, \==
Strictly not equal
<<
Strictly less than
¬<<, \<<
Strictly not less than
>>
Strictly greater than
¬>>, \>>
Strictly not greater than
<<=
Strictly less than or equal to
>>=
Strictly greater than or equal to

When you use the == comparison operator (strictly equal), the two character strings being compared must be identical (character by character) and of the same length to be considered strictly equal. Leading and trailing blanks are significant. For example, continuing the example using field #4 that contains the value MixedCase, only the first of the following comparison operations would be true:

#4 == 'MixedCase'
#4 == '    MixedCase     '

Similarly, the strict comparison operators such as >> or << carry out a simple character-by-character comparison, with no padding of either of the strings being compared. The comparison of the two strings is from left to right. If one string is shorter than and is a leading substring of another, then it is smaller than (less than) the other. The strict comparison operators do not attempt to perform a numeric comparison on the two terms, and should not be used to compare numeric fields.