... required. If the loop-continuation condition is initially false, the program does not execute the for statement’s body. Instead, execution proceeds with the statement following the for.

Representing a for Statement with an Equivalent while Statement

The for statement often can be represented with an equivalent while statement as follows:


initialization;

while (loopContinuationCondition) {
   statement
   increment;
}

In Section 5.10, we show a case in which a for statement cannot be represented with an equivalent while statement. Typically, for statements are used for counter-controlled iteration and while statements for sentinel-controlled iteration. However, while and for can each be used for either iteration type.

Scope of a for Statement’s Control ...

Get C++ How to Program, 10/e now with O’Reilly online learning.

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