Loops :
A block of statements executed repeatedly until a condition
is true.this is called loop.
There are three types of loop.
- 1. While loop
- 2. Do—while loop
- 3. For loop
While loop
A variable is initialized
first then it is compared with a value. Until
that condition is true the statements inside the loop will be executed repeatedly. The counter
variable will be incremented or decremented
inside the loop.
Example-1
#include <stdio.h>
int main()
{
int i=1;
while(i<=10)
{
printf("%d\n",i);
i++;
}
return 0;
}
Output:
Example-2:
#include <stdio.h>
int main()
{
int i=1,sum=0;
while(i<=10)
{
sum=sum+i;
i++;
}
printf("sum
from 1+2--+3=%d",sum);
return 0;
}
Output:
--------------will continue,
Thanking you
------Muthu karthikeyan,Madurai
No comments:
Post a Comment