Comparison (Relational) Operators
Language Items List
Definition:
Compares two expressions and determines their relationship.
Syntax:
result = expr1 operator expr2
Details:
Comparison, or relational, operators compare two expressions from left to
right in the order they appear. Comparison operators are performed after any
arithmetic operators, unless they have been modified by parentheses.
Using comparison operators, your program can determine if the value of one
expression is equal to, greater than or less than the other. They are commonly
used to create decision making sections in your programs. These relational
operators return a value that represents the result of the test; -1 for true, 0 for
false.
The following table lists the comparison operators and the possible settings
for result:
Operator Description Result=True(-1) Result=False (0)
= Equal to expr1 = expr2 expr1 expr2
<> Not equal to expr1 expr2 expr1 = expr2
< Less than expr1 < expr2 expr1 expr2
<= Less than or expr1 expr2 expr1 > expr2
equal to
> Greater than expr1 > expr2 expr1 expr2
>= Greater than expr1 expr2 expr1 < expr2
or equal to
When comparing two expressions it is not always easy to determine whether the
expressions are being compared as numbers or as strings. The following table
shows when to compare expressions as a number or string:
Compare as... If...
Numeric - Both expressions are numeric data types (num, num)
String - Both expressions are String (string, string)
Note: A type mismatch exception is thrown if one expression is a numeric data type
and the other is a string that cannot be converted to a number (num, string).
See Also:
Logical operators
StrComp