For Loop in C
This article is about the for loop in C programming and how it can be used in your programs.
Introduction - For Loop
For loop is a repetition control structure that executes a sequence of statements multiple times as required for the program.
In for loop, the initialization is done only once and then the condition is checked. If the condition returns true, statements inside the body of the loop are executed and then the update statement is performed and again evaluates the condition.
But if the condition returns false then the loop is terminated. The ‘for loop’ in the C language is basically used to iterate the statements or the part of a program repeated times. For loop can be used when the number of iterations are known. i.e number of times the statements to be executed.
Syntax
for (initialization Statement; condition; update Statement)
{
//statements inside the body of loop
}
Example
#include <stdio.h>
int main()
{
int i = 1;
while (i <= 7)
{
printf("%d ", i);
++i;
}
return 0;
}
Output
1 2 3 4 5 6 7