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.
3.140.197.10