UDM - if Statement - Comparison Operations

UDM - if Statement - Comparison Operations

In an if statement, a comparison consists of three parts:

  • Left-hand value
  • Comparator
  • Right-hand value

The left-hand and right-hand values can be either:

  • Variable reference
  • Variable attribute
  • Constant

Comparators

A comparator determines the type of comparison to be made between the left-hand and right-hand values.

There are six comparators:

 

EQ - Equal

The equal comparator, EQ, evaluates to true if both the left and right-hand values are equal to each other. If one or more of the values contains alpha characters (non-numeric), the comparison is case insensitive. That is, a word that is all lower case would be equal to the same word if it were all upper case (for example: dog would be equal to DOG).

The following are examples of if statements using the equal comparator, EQ:

if $(filename) EQ myfile.txt
print msg="The name of the file is myfile.txt"
end*

if 8 EQ $(_lastrc)
print msg="The last command resulted in an error"
end

if $(filename.exists) EQ yes
print msg="The filename variable exists"
end


NE - Not Equal

The not-equal comparator, NE, evaluates to true if the left-hand value is not the same as the right-hand value. As with the equal comparator, EQ, alpha character comparisons are case insensitive.

The following are examples of if statements using the not-equal comparator, NE:

if "C:\Program Files\Universal" NE $(mydir)
print msg="This is not the Stonebranch application directory"
end

if 8 NE 0
print msg="This will always print as 8 is not equal to 0"
end

if $(filename.exists) NE no
print msg="The filename variable exists"
end


LT - Less Than

The less than comparator, LT, evaluates to true if the left-hand value is less than the right-hand value. The less than comparator performs a numeric comparison.

The following are examples of if statements using the less than comparator:

if 0 LT 8
print msg="0 is less than 8"
end

if $(_rc) LT 8
print msg="No errors have occurred"
end

if $(filename.length) LT 8
print msg="The length of the filename is less than 8"
end


GT - Greater Than

The greater than comparator, GT, evaluates to true if the left-hand value is greater than the right-hand value. As with the less than comparator, LT, the comparison is between two numeric values, as shown in this example:

if 8 GT 0
print msg="8 is greater than 0"
end


LE - Less Than or Equal

The less than or equal comparator, LE, is similar to the less than comparator, LT, except that it evaluates to true if the left-hand value is less than or equal to the right-hand value, as shown in these examples:

if 8 LE 8
print msg="8 is less than or equal to 8"
end

if $(filename.length) LE 8
print msg="The length of the filename is less than or equal to 8"
end


GE - Greater Than or Equal

The greater than or equal comparator, GE, is similar to the greater than comparator, GT, except that it evaluates to true if the left-hand value is greater than or equal to the right-hand value, as shown in this example:

if $(filename.length) GE 9
print msg="The filename is longer than 8 characters"
end