Comparison Operators

A comparison operator compares its operands and returns a logical value based on whether the comparison is true or not. The operands can be numerical or string values. When used on string values, the comparisons are based on the standard lexicographical ordering.

The following table describes the comparison operators. It assume var1 has been assigned the value 3 and var2 has been assigned the value 4.

OperatorDescription

==

(Equal) Returns true if the operands are equal. For example:

3 == var1

!=

(Not equal) Returns true if the operands are not equal. For example:

var1 != 4

>

(Greater than) Returns true if left operand is greater than right operand. For example:

var2 > var1

>=

(Greater than or equal) Returns true if left operand is greater than or equal to right operand. For example:

var2 >= var1
var1 >= 3

<

(Less than) Returns true if left operand is less than right operand. For example:

var1 < var2

<=

(Less than or equal) Returns true if left operand is less than or equal to right operand. For example:

var1 <= var2
var2 <= 5