The syntax of a for loop is the following:
for (
expr-1 ;
expr-2 ;
expr-3 )
statement
This is equivalent to the following construct using while:
expr-1 ;
while ( expr-2 ) {
statement
expr-3
;
}
Typically, expr-1 is an assignment, expr-2 is a relational expression, and expr-3 is an increment or decrement of some manner. For example, the following code counts from 0 to 99, printing each number along the way:
int i; for (i= 0; i < 100; i++) printf("%d\n", i);