for loop :
The for is an entry control looping statements.first initialization will takes places,After initialization it check the condition,After check the condition,if the condition is non-zero it will enter into the body execute the statements and gofor updation statements it's once again check the condition if it is non-zero.same process is repeated.
The for loop is the more flexible compare to the all other loops.the for rotates in anti-clockwise direction .In for loop every thing is optional.In for loop we can perform any no.of initializations,condition checking is separated by the comma operator.
Syntax :
for(initialize counter;test condition;re-evaluation parameter)
{
statement 1:
statement 2:
statement n;
}
with out body :
#include<stdio.h>
main()
{
int a,b;
for(a=b=1;a;printf("%d %d",a,b))
a=b++<=3;
printf("\n %d %d ",a+10,b+10);
}
OUTPUT :
1 2
1 3
1 4
1 5
10 15
with semi column :
#include<stdio.h>
main()
{
int a;
for(a=1;a<10;a++);
printf("\t%d",a);
}
OUTPUT :10
The for is an entry control looping statements.first initialization will takes places,After initialization it check the condition,After check the condition,if the condition is non-zero it will enter into the body execute the statements and gofor updation statements it's once again check the condition if it is non-zero.same process is repeated.
The for loop is the more flexible compare to the all other loops.the for rotates in anti-clockwise direction .In for loop every thing is optional.In for loop we can perform any no.of initializations,condition checking is separated by the comma operator.
Syntax :
for(initialize counter;test condition;re-evaluation parameter)
{
statement 1:
statement 2:
statement n;
}
points to remember :
1 ) Which of the statement will checking the condition that variable value has to change every time of repetition.
2 ) The variable will checking the condition that finally as to reach zero .
Example :
With body:
#include<stdio.h>
With body:
#include<stdio.h>
#include<conio.h>
main()
{
int i;
for(i=1;i<=10 ;i++)
{
printf("%d",i);
}
}
OUTPUT:
12345678910
#include<stdio.h>
main()
{
int a,b;
for(a=b=1;a;printf("%d %d",a,b))
a=b++<=3;
printf("\n %d %d ",a+10,b+10);
}
OUTPUT :
1 2
1 3
1 4
1 5
10 15
with semi column :
#include<stdio.h>
main()
{
int a;
for(a=1;a<10;a++);
printf("\t%d",a);
}
OUTPUT :10