C for loop control

for loop control

for loop is used to execute a set of statements repeatedly until a particular condition is true. We can say it is an open ended loop.

The syntax of the for loop is as follows:

for (initialization; condition; increment/decrement)
{
    statement(s);
}    
#include
#include
void main(){
   int n; 
   /* for loop example */
   for( n = 1; n <= 5; n++ ){
      printf("value of n: %d\n", n);
   }
 getch();
}

Output

value of n: 1
value of n: 2
value of n: 3
value of n: 4
value of n: 5