for ( int counter=1; counter <= 10; counter++ )
where:
- for is a keyword
- counter is the control variable
- 1 is the initial value of control variable
- 10 is the final value of control variable
- counter <= 10 is the loop-continuation condition
- counter++ is the increment of control variable
The general format of the for structure is
for (expression1; expression2; expression3 )
statement
where expression1 names the loop's control variable and provides its initial value, expression2 is the loop-continuation condition (containing the control variable's final value) and expression3 modifies the value of the control variable, so that the loop-continuation condition eventually becomes false. In most cases, the for structure can be represented with an equivalent while structure, with expression1, expression2 and expression3 placed as follows:
expression1;
while ( expression2 ) {
statement;
expression3;
}
No comments:
Post a Comment