When the repetitions are required then go for loops, if complete loop body required to repeat n no. of times then go for nested loop.
In c prog.lang, we can place up to 255 nested blocks.
Syntax:
Assignment 1;
While (condition1)
{
Statement1;
Statement2;
- - - - - -
Assignment 2;
While (condition2)
{
Statement1;
Statement2;
- - - - -
Index
}
Inc/dec;
}
When we are working with nested loops, always execution is started from the outer loop condition i.e. condition1.
When the outer loop condition is true, then control will pass to the outer loop body.
In order to execute the outer loop body; if any while statements occur those are called inner loops.
When the inner loop occurs, we are required to check inner loop condition i.e. condition 2.
If inner loop condition is true then control will pass within the inner loop body and until the inner loop condition becomes false, body is repeated n no. of times, When inner loop condition is false then control will pass to outer loop and until the outer loop condition becomes false body is repeated n no. of times.