Comparison operators
- 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)
Note that 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.)
#4
contains the value
MixedCase
both the following comparison operations would be true:
#4 = 'MixedCase'
#4 = ' MixedCase '
#4 = MixedCase
#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).
- 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
==
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.