Foor loop
The general design of the for loop is reflected in some form or another in all procedural
programming languages. However, in C, it provides unexpected flexibility and power.
The general form of the for statement is
for (initialization; condition; increment) statement ;
The for loop allows many variations, but its most common form works like this: The initialization is
an assignment statement that is used to set the loop control variable. The condition is a relational
expression that determines when the loop exits. The increment defines how the loop control variable
changes each time the loop is repeated. You must separate these three major sections by semicolons.
The for loop continues to execute as long as the condition is true.
A simple program for understanding for loop of adding 1 to k and k will be read from users.
#include<stdio.h>
#include<conio.h>
void main()
{
int k,i,sum=0;
printf("Enter the number till you want your addition:");
scanf("%d",&k);
for(i=0;i<=k;i++)
{
sum=sum+i;
}
printf("The addition of numbers is %d",sum);
getch();
}