C Language


Java Tutorial


Admission Enquiry Form

  

Do While Loop in C

What is do-while loop in C?

do-while loop in C is an Unknown loop in C. It is used when the number of iteration are not known. It executes once before checking the condition.

Syntax of do-while loop.

do
{
//number of statements.
}while(condition);




Example of do-while loop:

#include<stdio.h>
int main()
{
int i;
i=1;
do
{
printf("i is = %d\n",i);
i++;
}while(i<=10); //end of do while loop
}//end of main


Output:

i is = 1
i is = 2
i is = 3
i is = 4
i is = 5
i is = 6
i is = 7
i is = 8
i is = 9
i is = 10

In the above example, the do-while loop will execute 10 times, first time the statement in do block will be executed before checking the condition, another nine times statement will be executed after checking the condition in while.