HP C A.06.05 Reference Manual
Expressions and Operators
Comma Operator (,)
Chapter 5 103
Comma Operator (,)
Syntax
exp1
,
exp2
Arguments
exp1
Any expression.
exp2
Any expression.
Description
Use the comma operator to separate two expressions that are to be evaluated one right after
the other. The comma operator is popular within for loops, as demonstrated by the following
example:
for (i = 10, j = 4; i * j < n; i++, j++);
In the preceding example, the comma operator allows you to initialize both i and j at the
beginning of the loop. The comma operator also allows you to increment i and j together at
the end of each loop iteration.
All expressions return values. When you use a comma operator, the expression returns the
value of the rightmost expression. For example, the following statement sets variable j to 2:
j = (x = 1, y = 2);
Assignments such as these, however, are considered poor programming style. You should
confine use of the comma operator to for loops.