Nested do-while loop in C Language Tutorials

This “Nested do-while loop C language Tutorial” post explains clearly about syntax, flow chart and execution flow of how a do-while loop executes when it presents inside another do-while loop.


 

Nested do-while loop :

  • Defining do-while loop inside another do-while loop.
  • Inner while loop executes only when outer loop condition is true.
  • Loop execution terminates when outer condition has failed.
    ‚Äč
Syntax:

do
{
Outer while statements ;
do
{
Inner while statements ;
}while(inner_cond);
Outer while statements ;
}while(outer_cond);

 

Code program:
void main()
{
int i=-1 , j=1;
do
{
do
{
j++;
}while(j++ <= 3);
i++;
}while(i++ < 3);
printf(” i : %d \n j : %d\n”,i,j);
}

Share this