------------------------------------------------------------------------------
MC logo
For Loops
[^] CSc 220 Home
------------------------------------------------------------------------------
[Introduction] [Boolean and Control] [Functions] [Arrays and Pointers] [Dynamic Arrays] [Array Errors] [Command Array] [Standard Containers] [Structs and Classes] [Automatic Pointer] [Multi-File Programs] [Copying Objects] [Templates] [Inheritance] [Plain C I/O] [Type Odds And Ends] [Plain C Strings] [File I/O]
[Counted Average Example] [For Loop Average] [For Loops] [Read-To-End Average] [Reading In the While Test] [Counting Example 1] [Counting Example 2] [Counting Example 3] [Counting Example 4] [Counting Example 5] [Watch Out For This] [Switch] [Switch Using Break] [Break and Continue] [Change Adder]
The for statement is similar to Java's.

Abbreviates a while loop.

for(init;test;incr)stmt
      Abbreviates...
init;while(test){stmt incr;}

for(i = 1; i <= 10; ++i) printf("%d\n", i);
      Abbreviates...
i = i; while(i <= 10) { printf("%d\n", i); ++i; }

Pure C forbade declarations in for loops until C99. Many compiliers will still forbid. it.