The Do/While Loop
The do/while loop is a variant of the while loop. This loop will execute the code
block once, before checking if the condition is true, then it will repeat the
loop as long as the condition is true.
The example below uses a do/while loop. The loop will always be executed
at least once, even if the condition is false, because the code block is
executed before the condition is tested:
#include <stdio.h>
int main()
int i = 0;
do {
printf("%d\n", i);
i++;
while (i < 5);
return 0;
//Write a program in c to print table
1. #include<stdio.h>
2. int main(){
3. int i=1,number=0;
4. printf("Enter a number: ");
5. scanf("%d",&number);
6. do{
7. printf("%d \n",(number*i));
8. i++;
9. }while(i<=10);
10. return 0;
11. }
// Program to add numbers until the user enters zero
#include <stdio.h>
int main() {
double number, sum = 0;
// the body of the loop is executed at least once
do {
printf("Enter a number: ");
scanf("%lf", &number);
sum += number;
}
while(number != 0.0);
printf("Sum = %.2lf",sum);
return 0;
}
#include<stdio.h>
int main()
int num, sum = 0;
while(num!=0)
printf(“Enter a number:”);
scanf(“%d”, &num);
sum = sum + num;
printf(“sum = %d”, sum);
getch();