Next: The while statement Up: Looping and Iteration Previous: Looping and Iteration

The for statement

The C for statement has the following form:

expression initialises; expression is the terminate test; expression is the modifier (which may be more than just simple increment);

NOTE: C basically treats for statements as while type loops

For example:

...outputs: the screen

All the following are legal for statements in C. The practical application of such statements is not important here, we are just trying to illustrate peculiar features of C for that may be useful:-

The second example shows that multiple expressions can be separated a ,.

In the third example the loop will continue to iterate until z becomes 0;
Wed Sep 14 10:06:31 BST 1994