Do while loop in C Language:
The do-while loop is a post-tested loop. Using the do-while loop, we can repeat the execution of several parts of the statements. The do-while loop is mainly used in the case where 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: When you want to execute the loop body at least once irrespective of the condition, then you need to use the do-while loop.
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 to use the nested do-while loop in C language is given 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; }