Do while loop in C
In this article you will get to know about the do..while loop in C programming and the usage of it.
Do while loop in C
The function of do….while loop is similar to while loop but with a change in the structure, the do….while loop in C programming checks the condition at the bottom of the loop.
A do...while loop is guaranteed to execute at least one time.
A do….while loop is just like an inverted while loop. It is used in the situations where you know that the code contained in the body of the loop should always need to be executed at least once.
Unlike while loop, even when the condition is false, the do…while loop will be executed once.
Syntax
do
{
//statements inside the body of the loop
}
while (condition);
Example
#include<stdio.h>
int main(){
int x = 1;
int y = 5;
do{
printf("%d ", x);
++x;
}while (x <= y);
return 0;
}
Output
1 2 3 4 5