Do While Statement in C Programming

like a while statement,  “ do while statement” repeats a set of statements if condition is true.

If condition is false the flow of control do not enter inside the do-while loop.

“do-while” first execute the body of loop than tests the condition.

Means even if the condition if false do-while executes at least ones.

The syntax of a do…while loop in C programming language is −

Example: Write a program to print 1 to 10 using while loop.

#include int main() {int a = 1;do { printf(” %d \n”, a); a++; } while (a <= 10); // loop executes 10 times return 0; }

OUTPUT

Even if the condition if false do-while executes at least ones.

#include int main() { int a = 100;do { printf(” %d \n”, a); a++;} while (a <= 10); // condition is false even do-while executes ones return 0; }

OUTPUT