While loop :
The while is a entry control looping statements. First it check the condition,if the condition satisfy's . It will enter into the body and will execute the statements. once the body is closed,if once again repeat the the process by checking the condition .
This process is continues untill the condition is false.
The while is a entry control looping statements. First it check the condition,if the condition satisfy's . It will enter into the body and will execute the statements. once the body is closed,if once again repeat the the process by checking the condition .
This process is continues untill the condition is false.
syntax :
Initialization ;
while( condition )
{
statement 1:
statement 2:
statement n;
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 ( )
main ( )
{
int i=1;
while(i<=10)
{
printf("%d",i);
i++;
}
getch( );
}
output : 12345678910
with out body:
#include<stdio.h>
main()
{
int i=0;
while(i++<10)
printf("%d",i);
getch();
}
OUTPUT :
12345678910
with semi column :
#include<stdio.h>
main()
{
int i=0;
while(i<10);
printf("%d",i);
i++;
getch();
}
with out body:
#include<stdio.h>
main()
{
int i=0;
while(i++<10)
printf("%d",i);
getch();
}
OUTPUT :
12345678910
with semi column :
#include<stdio.h>
main()
{
int i=0;
while(i<10);
printf("%d",i);
i++;
getch();
}
OUTPUT:
nothing will be display
nothing will be display