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
do { statements; } 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; num=1; do { printf("%d \\n",num); num++; } while (num <= 10); return 0; }
Nothing yet..be the first to share wisdom.