Do While - 1
Do While - 1
Do While - 1
while loop
The do..while loop is similar to the while loop with one important difference. The body of
do...while loop is executed at least once. Only then, the test expression is evaluated.
do
{
// statements inside the body of the loop
}
while (testExpression);
The body of do...while loop is executed once. Only then, the test expression is evaluated.
If the test expression is true, the body of the loop is executed again and the test
expression is evaluated.
This process goes on until the test expression becomes false.
If the test expression is false, the loop ends.
#include <stdio.h>
intmain()
{
double number, sum = 0;
printf("Sum = %.2lf",sum);
return 0;
}
Output
Example 2
#include <stdio.h>
Int main()
{
int counter;
int marks;
int total;
int average;
total = 0;
counter =1;
do
{
printf(“enter marks”);
scanf (“%d”,&marks);
total= total +marks;
counter = counter+1;
}
while (counter<=10)
average=total/counter;
printf(“class average is %d\n”, average);
return 0;
}
Example 3
#include <stdio.h>
intmain()
{
inti = 1;
do
{
printf("%d\n", i);
++i;
while (i<= 5)
}
return 0;
}