- Setting a loop counter to an initial value
- Testing the loop counter to determine whether its value has reached the number of repetitions desired.
- Increasing or Decreasing the value of loop counter.
The initialisation expression of the for loop can contain more than one statement by a comma.For example:
for(i=0, j=10; i<=j ; i++,j--)
for(i=0, j=10; i<=j || i==j ; i++,j--)
The way if statement can be nested, similarly whiles and fors can also be nested. Let's understand the nesting of for loops through program:
for(c=1; c<=2; c++) /*inner loop*/
printf("r=%d c=%d sum=%d\n",r,c,s);
Thus we see in above program that, the body of outer loop is indented, and the body of the inner for loop is further indented. These multiple indentations make the program easier to understand.