Nested do…while Loop in C
As with other loops, we can also nest one do…while loop into another loop. It is demonstrated using the following C program.
Example of Nested do…while Loop in C:
C
// C Program to demonstrate the nesting of do...while loop #include <stdio.h> int main() { // declaring loop variables int i = 0, j; int count = 0; // outer loop starts do { j = 0; // inner loop starts do { printf ( "%d " , count++); j++; } while (j < 3); // inner loop ends printf ( "\n" ); i++; } while (i < 3); // outer loop ends return 0; } |
0 1 2 3 4 5 6 7 8
To know more about nested loops in C, refer to this article – Nested Loops in C with Examples
do…while Loop in C
Loops in C language are the control flow statements that are used to repeat some part of the code till the given condition is satisfied. The do-while loop is one of the three loop statements in C, the others being while loop and for loop. It is mainly used to traverse arrays, vectors, and other data structures.