C Do...While Loop

The do...while loop is a variant of the while loop. It is similar to the while loop except that the condition check happens at the end of the loop. This means that the loop will always be executed at least once, even if the condition is false. The Syntax of do...while loop is as follows :
do {
  code to be executed
} while ( condition is true );
For example, the below code will print "Hello world" five times.
#include <stdio.h>

int main() {
  int count = 0;

  do {
    printf("Hello world!\n");
    count++;
  } while(count < 5);

  return 0;
}
Output :

Hello world!
Hello world!
Hello world!
Hello world!
Hello world!

The next example will print the table of 2.
#include <stdio.h>

int main() {
  int count = 1, num = 2;

  do {
    printf("%d\n", count*num);
    count++;
  } while(count <= 10);

  return 0;
}
Output :

2
4
6
8
10
12
14
16
18
20

Next Topic :