For Loop in C



Syntax
        for(initialization;condition;iteration)
     {
           body of loop;
     }
Here,
Initialization: It indicates the starting point for the loop. Starting point specifies from which value the loop will start the iteration.
Condition:It indicates control condition for the loop. Control condition determines when loop will stop.
Iteration: It indicates how the value of the counter variable that holds the starting value will vary. You can either increment or decrement the value of the counter variable based on your requirement.

for loop is used to repeatedly perform some task for specific number of times. It is also known as iterative statement. It is useful when you know in advance how many times you want to repeat the task.

     

In for loop first the counter variable is initialized with the starting value in the initialization part. After initialization the condition is checked. If the condition is true then the statements written inside body of loop will executes. After executing statements inside body of loop the control goes to the Iteration part where the value of the counter variable is incremented or decremented. After changing the value of the counter variable it again check the condition.
This process is repeated until condition specified within for loop becomes false. As the condition becomes false the statements inside body of loop will not executes and control transfer immediately to the statement followed by for loop.  

Example
int i;
for (i=1;i<=10;i++)
{
   printf(" %d ",i);
}
It will display
1 2 3 4 5 6 7 8 9 10 
 

Download Projects


Download Programs