While statement is also called while loop.The way to write while statement is :
while (condition)
statement;
Here condition is any of True C- Programming Expression.Usually relational expressions used here.While statement calculate the value of condition at first.
If the calculated value of condition become true than while statement will be executed but if the calculated value of condition become false than the statement will not be executed....
Watch the program very carefully :
#include<stdio.h>
#include<conio.h>
main()
{
int i;
i=1;
while(i<=10)
{
printf("%d",i);
i++;
}
getch();
}
OUTPUT :
1,2,3,4,5,6,7,8,9,10
Program Analysis :
->i is initialized first of all.i=1
->while(i<=10)
So the first expression is true and body of while will execute.
->Value of i will be printed and i will be increased by 1 so the value of i is now 2.
->again for the value of i is true according to the condition(i<=10)
->So when the value of i will be 11,the condition will be false and while loop will end.
Post a Comment