Nested loop

Loop will repeat statements. Each repetition is called an iteration.A loop can be nested as many times as required. To avoid complexity we show a loop inside another loop. All iteration of inner loop will be completed during each iteration of immediate outer loop.
Example:

#include<stdio.h>
int main()
{
      int x,y;
      for(x=1;x<5;x++)
      {
           printf("Outer loop iteration %d\n",x);
           for(y=1;y<5;y++)
            {
                printf("\t Inner loop iteration %d\n",y);
            }
      }
      return 0;
}

 

OUTPUT

Outer loop iteration 1
Inner loop iteration 1
Inner loop iteration 2
Inner loop iteration 3
Inner loop iteration 4
Outer loop iteration 2
Inner loop iteration 1
Inner loop iteration 2
Inner loop iteration 3
Inner loop iteration 4
Outer loop iteration 3
Inner loop iteration 1
Inner loop iteration 2
Inner loop iteration 3
Inner loop iteration 4
Outer loop iteration 4
Inner loop iteration 1
Inner loop iteration 2
Inner loop iteration 3
Inner loop iteratio


Next Previous