{ A destination to learn coding }

Iteration Statements

Do While Loop

The for loop and the while loop tests the loop condition at the top of the loop. Whereas the do-while loop test at the bottom of the loop. This allows the do-while loop to execute at least once.


do
{
statement;
}
while(condition);

This loop wont execute since the condition is false.
for(i=0;i>10;i++)
{
statement;
}

But the loop below executes once although the condition is false.
int i=0;

do
{
printf("Hii");
} while(i>10);


Re-writing the for loop's Hello world program using do-while loop
#include<stdio.h>
int main()
{
 int i=0;

 do
 {
 printf("Hello World\n");
 i++;
}while(i<10);

 printf("Done");
 return 0;
}
Try this
Printing table of any number
Display first 10 natural numbers
Find factorial of a number
Code to check for a prime number.
Fibonacci Series
You can even try printing patterns
C Codes