In some situations it is necessary to execute body of the loop before testing the condition.
Such situations can be handled with the help of do-while loop.
do statement evaluates the body of the loop first and at the end, the condition is checked using while statement.
General format of do-while loop is,
do
{
.....
.....
}
while(condition)
//Write a Program to Print First 10 Natural Numbers using do while loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
i = 1;
do
{
printf("%d ", i);
i++;
}
while(i <= 10)
getch();
}
Ask Question