for Statement Header Components

Figure 5.3 takes a closer look at the for statement header (line 10) of Fig. 5.2. Notice that the for statement header “does it all”—it specifies each of the items needed for counter-controlled repetition with a control variable. If there’s more than one statement in the body of the for, braces are required to enclose the body of the loop. Typically, for statements are used for counter-controlled repetition and while statements are used for sentinel-controlled repetition.


Fig. 5.3. for statement header components.

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.