Examples on Nested Loops
For Complete YouTube Video: Click Here
In this class, we will try to understand Examples on Nested Loops.
We have already discussed the Nested Loops.
Example
The image below is a programming example for nested loops.
In the above program, we have taken three variables, i, j, and k.
The variables are used in the for loops.
The program uses three-level loops.
The outermost loop, inner loop and innermost loop.
From the above example, how many times the LM will be printed.
From the above example, it is clear that the outer loop will iterate for times.
Every time we enter the outer loop, the inner loop will iterate two times.
We enter the outermost loop two times so that the inner loop will iterate four times.
Similarly, every time we enter the inner loop, the innermost loop will iterate two times.
As we enter the inner loop four times, the innermost loop will iterate eight times.
Finally, the LM will be printed eight times.