Back to: C Tutorials For Beginners and Professionals
Do While Loop in C Language with Examples
In this article, I am going to discuss the Do While loop in C Language with Examples. Please read our previous articles discussing While loop in C Language with Examples. At the end of this article, you will understand what is the do-while loop and when and how to use a do-while loop in the C Program with examples.
Do while loop in C Language:
Using the do-while loop, we can repeat the execution of several parts of the statements. The do-while loop is mainly used when we need to execute the loop at least once. The do-while loop is mostly used in menu-driven programs where the termination condition depends upon the end user.

Syntax to use Do While Loop in C:

Program to understand do while loop in c:
#include <stdio.h>
int main()
{
int j=0;
do
{
printf("Value of variable j is: %d\n", j);
j++;
}while (j<=3);
return 0;
}
Output:

Note: You need to use the do-while loop when you want to execute the loop at least once, irrespective of the condition.
Nested Do-While Loop in C Language:
Using a do-while loop within do-while loops is said to be a nested do-while loop. The syntax for using the nested do-while loop in C language is below.

Program to Understand Nested do-while Loop in C Language:
#include <stdio.h>
int main ()
{
do
{
printf ("I'm from outer do-while loop ");
do
{
printf ("\nI'm from inner do-while loop ");
}
while (1 > 10);
}
while (2 > 10);
return 0;
}
Output:
![]()
In the next article, I am going to discuss For Loop in C Language with examples. In this article, I try to explain Do While Loop in C Language with examples. I hope you enjoy this Do While Loop in C Language with Examples article. I would like to have your feedback. Please post your feedback, questions, or comments about this article.
