General Format of a for Statement

The general form of the for statement is

for ( initialization; loopContinuationCondition; increment )   statement

where the initialization expression initializes the loop’s control variable, loopContinuationCondition determines whether the loop should continue executing and increment increments the control variable. In most cases, the for statement can be represented by an equivalent while statement, as follows:

initialization;while ( loopContinuationCondition ){   statement   increment;}

There’s an exception to this rule, which we’ll discuss in Section 5.7.

If the initialization expression declares the control variable (i.e., its type is specified before its name), the control variable can be used only

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.