Rexx Programming/How to Rexx/comparative operator
The comparative operators are used to determine equality or inequality or otherwise make comparisons of numeric or string values, and produce a boolean truth based on the result. A true comparison evaluates to a value of one, whereas a false comparision evaluates to zero.
Numeric or String Comparisons
[edit | edit source]The variables in rexx are typeless, so the interpreter decides whether to make a numeric or string comparison based upon the values of the operands to the operator being evaluated. If both operands contain a numeric value, then the comparison will be a numericcomparison, otherwise a stringcomparison will be made.
'21' = '21' /* 1 true, numeric comparison */ '021' = '21' /* 1 true, numeric comparison (leading zero ignored) */ ' 021 ' = '21' /* 1 true, numeric comparison (whitespace and leading zero ignored) */ '21' = '21.0' /* 1 true, numeric comparison (insignificant zero ignored) */ 'ABC' = 'Abc' /* 0 false, string comparison (case sensitive) */ ' ' = /* 1 true, string comparison (stripped whitespace matches null value) */ 'ABC' = ' ABC ' /* 1 true, string comparison (leading and trailing whitespace ignored) */
Strict Comparison
[edit | edit source]The conventional stringcomparison operators ignore leading and trailing whitespace when the comparison is made:
' ' = /* 1 true, string comparison (stripped whitespace matches null value) */ 'ABC' = ' ABC ' /* 1 true, string comparison (leading and trailing whitespace ignored) */
The rexx interpreter provides support for strict comparative operators. The strict comparative operators do not ignore leading and trailing whitespace, which must also match when a strict comparison is made.
' ' == /* 0 false, strict comparison (the spaces will not match the null value) */ 'ABC' == ' ABC ' /* 0 false, strict comparison (leading and trailing whitespace causes mismatch) */