Nested loops are very common in programming, when we have to call a loop multiple times. For e.g., printing
1 2 3 4 5 , can be done using a loop, but for printing it four times will need a loop inside a loop, also called as nested loops.
1 2 3 4 5
while(condition1) { while(condition2) { while(condition3) { ...... } } }
while(condition1) { while(condition2) { } while(condition3) { } while(condition4) { } ... }
while(condition1) { for(int i = 0; i < 5; i++) { while(condition2) { } for(int i = 0; i < 5; i++) { } } while(condition3) { } }
|