< (less than)

operator

Return type:
Switch
Returns:
True if the first expression evaluates to less than the second one does, and false otherwise.
Syntax
expression1 < expression2


Purpose

You can determine whether one expression is less than another with the < operator. You can use it with any data type expression. String expressions are compared according to the byte values of their characters.

To compare BCD numbers, you must import the ombcd.xmd file in your program. To compare floating point numbers, import the omfloat.xmd file. You can compare values of mixed data types (for example, BCD numbers and integers) as long as you follow the rules listed in Operations with mixed data types.

For example:

  ; Comparing strings
  process
     local stream string-1 initial {"Catch-up"}
     local stream string-2 initial {"Catch-22"}
     do when string-1 < string-2
        output string-1
            || " < "
            || string-2
            || "%n"
     else when string-1 > string-2
        output string-1
            || " > "
            || string-2
            || "%n"
     else when string-1 = string-2
        output "String compare has an error."
            || "%n"
     done
  ; Output: "Catch-up > Catch-22"

The following tests use "<" to compare strings. The first and third tests evaluate as true; the second evaluates as false.

  do when "a" < ul "b"
  ...
  done
  
  do when "a" < "B"
  ...
  done
  
  do when  "a" < "b"
  ...
  done

You can also compare two variables of different data types, for example, an integer and a BCD. If their numeric values are the same, one will not compare greater than the other.

  import "ombcd.xmd" unprefixed
  process
     local integer one-integer initial {33}
     local bcd one-bcd initial {33}
     do when (one-bcd < one-integer)
        output "Error. BCD of "
            || "d" % one-bcd
            || " shown as less than integer of "
            || "d" % one-integer
            || ".%n"
     else
        output "Correct. BCD of "
            || "d" % one-bcd
            || " shown as not less than integer of "
            || "d" % one-integer
            || ".%n"
     done
  ; Output: "Correct. BCD of 33 shown as not less than integer of 33."

This operator has two deprecated synonyms: is less-than and isnt greater-equal.