for Statement: Notes and Observations

The initialization, loop-continuation condition and increment expressions of a for statement can contain arithmetic expressions. For example, if x = 2 and y = 10, and x and y are not modified in the loop body, the for header

for ( unsigned int j = x; j <= 4 * x * y; j += y / x )

is equivalent to

for ( unsigned int j = 2; j <= 80; j += 5 )

The “increment” of a for statement can be negative, in which case it’s really a decrement and the loop actually counts downward (as shown in Section 5.4).

If the loop-continuation condition is initially false, the body of the for statement is not performed. Instead, execution proceeds with the statement following the for.

Frequently, the control variable is printed or ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.