do ... while loop

The do ... while loop is very similar to the while loop except that the condition is checked at the end of the loop. In case of do ... while loops the set of statements are executed at least once whereas in a while loop the statements may not be executed at all if the condition is false initially.

do ... while loops are written in the form

while (condition)

The statements within curly braces are executed once and then the condition is evaluated. The loop will then repeat until the condition is False or 0


Here is an example of a program that prints the numbers from 1 to 10 using do ... while loop.

#include <stdio.h>

int main() {
int num;
do {
	printf("%d \\n",num);
} while (num <= 10);

return 0;

Post a comment


Your Comment

Email (We dont publish it)


Nothing the first to share wisdom.