HP C A.06.05 Reference Manual
Expressions and Operators
Relational Operators (>, >=, <, ==, !=)
Chapter 5126
Relational Operators (>, >=, <, ==, !=)
Syntax
exp1
>
exp2
Greater than.
exp1
>=
exp2
Greater than or equal to.
exp1
<
exp2
Less than.
exp1
<=
exp2
Less than or equal to.
exp1
==
exp2
Equal to.
exp1
!=
exp2
Not equal to.
Arguments
exp1
Any expression.
exp2
Any expression.
Description
A relational expression consists of two expressions separated by one of six relational
operators. The relational expression evaluates either to 1 (true) or 0 (false).
The equality operator (==) performs the same function as Pascal's = or Fortran's .EQ.; it just
looks different. Although the equality operator looks similar to the assignment operator (=),
the two operators serve completely different purposes. Use the assignment operator when you
want to assign a value to a variable, but use the equality operator when you want to test the
value of an expression.
Confusing = with ==
One of the most common mistakes made by beginners and experts alike is to use the
assignment operator (=) instead of the equality operator (==). For instance:
while (j = 5)
do_something();
What is intended, clearly, is that the do_something() function should only be invoked if j
equals five. It should be written