For Loops:


Here's the syntax:


for (counter = 0; counter < some limit; counter++)
{
    do something;
}

For example:

#include <stdio.h> void main( ) { int counter, limit; limit = 10; /* counter++ can be used in short for the expression counter = counter + 1 */ for (counter = 0; counter < limit; counter++) { printf("Counter = %d\n", counter); } printf("\nOut of the loop!\n"); }

 

Here's the output:

UNIX prompt >> a.out

Counter = 0

Counter = 1

Counter = 2

Counter = 3

Counter = 4

Counter = 5

Counter = 6

Counter = 7

Counter = 8

Counter = 9

Out of the loop!


Here's how the loop executes: