Next: while () {}
Up: Loops
Previous: Loops
Contents
Index
Simple for () {}
for (i=0; i<N; i++) {
statement_1;
statement_2;
.....
}
The general form
for (initialization_statement; continuation_condition; iteration_command) {
statement_1;
statement_2;
...
}
is analagous to that in Perl - in this,
- initialization_statement is the statement to execute when the
loop is first entered;
- continuation_condition is the condition that must be satisfied
in order that the next iteration take place;
- iteration_command is the command to be executed each time
through the loop;
If there is only one statement to be iterated over, the
matching curly braces may be omitted:
for (i=0; i<N; i++)
statement;