For Loop in C


Learn C - C tutorial - For loop in c - C examples - C programs

For Loop in C - Definition and Usage

  • In C- Programming the for loop is used to execute a set of statements repeatedly until a particular condition is satisfied. We can say it an open ended loop. General format is,
C For Loop Statement

C Syntax

for(initialization; condition ; increment/decrement)
  • In for loop we have exactly two semicolons, one after initialization and second after condition.
  • In this loop we can have more than one initialization or increment/decrement, separated using comma operator.
  • for loop can have only one condition.

Sample - C Code

void main ()
    int i,n=5;
    for( i= 1; i <= n; i++ )
     printf("C for loops: %d\n", i);

C Code - Explanation :

  1. Here in this statement we declare the variable “i” and initialize the value of “n=5”.
  2. In this statement we execute the for loop, while executing the first value of the for loop defines the initialization value as “i=0” and the next value is the conditional checking value and the third value as increment (or) decrement process here “i” value will be incremented.
  3. In this statement we are printing the value of “i”.

Sample Output - Programming Examples

  1. Here in this output the “i” value is incremented by one for each for loop execution which will be executed until the “i” value is less than are equal to “5”.

View More Quick Examples

Related Searches to C For Loop Statement