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,
for(initialization; condition; increment/decrement)
{
statement-block;
}
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.
//Write a Program to Print First 10 Natural Numbers using for loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
for(i=1; i<=10; i++)
{
printf("%d ",i);
}
getch();
}
Ask Question