
Adding a semicolon after
the closing parenthesis in
the for loop header indi-
cates an empty loop body
and will likely cause a logic
error.
COMMON ERROR
TRAP
6.10 Count-Controlled Loops Using for 331
6.10 Count-Controlled Loops Using for
Before the loop begins, if you know the number of times the loop body
should execute, you can use a count-controlled loop. The for loop is designed
for count-controlled loops, that is, when the number of iterations is deter-
mined before the loop begins.
6.10.1 Basic Structure of for Loops
The for loop has this syntax:
for ( initialization; loop condition; loop update )
{
// loop body
}
Notice that the initialization, loop condition, ...