|
Executes a block of statements for as long as a specified condition is true.
for (initialization; test; increment)
statement
initialization
An expression. This expression is executed only once, before the loop is executed.
test
A Boolean expression. If test is True, statement is executed. If test if False, the loop is terminated.
increment
An expression. The increment expression is executed at the end of every pass through the loop.
statement
The statement to be executed if test is True. Can be a compound statement.
You usually use a for loop when the loop is to be executed a specific number of times as the following example demonstrates:
/* i is set to 0 at start, and is incremented by 1 at the end
of each iteration. Loop terminates when i is not less
than 10 before a loop iteration. */
for (i = 0; i < 10; i++)
{
j *= i;
}
Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.