C

do while loop

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,

Syntax:

do
{
     .....
     .....
}
while(condition)

Example:

//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();
}

Output:

Command Prompt
1 2 3 4 5 6 7 8 9 10



Subscribe us on Youtube

Share This Page on

Question


Rajan | 24-Apr-2016 09:49:07 pm

Working:)


Ask Question