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,
- 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
C Code - Explanation :
- Here in this statement we declare the variable “i” and initialize the value of “n=5”.
- 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.
- In this statement we are printing the value of “i”.
Sample Output - Programming Examples
- 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”.