Expressions that use comparison operators do not return a number
value as do arithmetic expressions. Comparison expressions return
either 1, which represents true, or 0, which
represents false.
Comparison operators can compare numbers or strings and perform
evaluations, such as:
- Are the terms equal? (A = Z)
- Is the first term greater than the second? (A > Z)
- Is the first term less than the second? (A < Z)
For example, if
A = 4 and
Z = 3, then the
results of the previous comparison questions are:
(A = Z) Does 4 = 3? 0 (False)
(A > Z) Is 4 > 3? 1 (True)
(A < Z) Is 4 < 3? 0 (False)
The more commonly used comparison operators are as follows:
- Operator
- Meaning
- =
- Equal
- ==
- Strictly Equal
- \ =
- Not equal
- \ ==
- Not strictly equal
- >
- Greater than
- <
- Less than
- > <
- Greater than or less than (same as not equal)
- > =
- Greater than or equal to
- \ <
- Not less than
- < =
- Less than or equal to
- \ >
- Not greater than
Note: The NOT character (¬)
is synonymous with the backslash (\). You can use the two
characters interchangeably according to availability and personal
preference. This book uses the backslash (\) character.