for LOOP : For statement « Statement « C Tutorial






The for loop is usually used when the number of iterations is predetermined.

The format of the for loop is

for (expr1;expr2;expr3){
        s1;
        s2 ;
    }
  1. expr1 is executed only once before looping.
  2. expr2 is a Boolean expression. If not given, it is assumed to be true.
  3. If expr2 is false, the loop is terminated.
  4. After execution of the repeat section, expr3 is executed
  5. The expressions expr1, expr2 and expr3 are all optional.
#include <stdio.h>

main(){
    int i,n = 5;
   
    for(i = 0; i < n; i = i+1){
       printf("the numbers are %d \n",i);
    }
}
the numbers are 0
     the numbers are 1
     the numbers are 2
     the numbers are 3
     the numbers are 4








6.6.For statement
6.6.1.for LOOP
6.6.2.Omit all three parts in for loop
6.6.3.The for loop with a comma operator
6.6.4.Initialize loop control variable outside the for statement
6.6.5.Use for loop to print a rectangle
6.6.6.Sum integers in for statement
6.6.7.for loop backward
6.6.8.indefinite loop: empty for
6.6.9.Nest if statement in for loop
6.6.10.Nest for loop: two different control variables
6.6.11.Use char variable to control for loop
6.6.12.Continue a for loop