“NESTED LOOP”
DEFINATION :-
A nested loop means a loop statement inside another loop statement.
That is why nested loop are also called “loop inside loops”. We can
define any number of loops inside another loop.
Recently we have learned about the NESTED FOR LOOP… NESTED
WHILE LOOP….also in we studied about BREAK and CONTINUE
statements in it…
USES AND REAL LIFE CONCEPT :-
Suppose we have to loops i.e one is OUTER LOOP and INNER LOOP.
and we need to repeat some action on the data in the outer loop. For
example, you read a file line by line and for each line you must count
how many times the word “the” is found. The outer loop would read
the lines and the inner loop would search each line for “the” by
looping through the words in the line.
SYNTAX :on; condition; increment ) {
Syntax for FOR loop –
For ( intializaiton ; condition ; increment;) {
For ( intializaiton ; condition ; increment;) {
// code
}
}
ADVANTAGES OF NESTED LOOP :-
Here are many advantages of nested loop….like :
1. Using loops, we do not need to write the same code again and
again.
2. Using loops, we can traverse over the elements of data structures
structures.
SOME EXTRA INFORMATION :-
Break inside Nested Loops ( break ; )
Whenever we use a break statement inside the nested loop sit breaks
the innermost loop and program control is inside the outer loop.
Break means to stop everything and terminate the loop.
Continue inside the Nested Loops ( continue ; )
Whenever we use a continue statement inside the nested loops it skips
the iteration of the innermost loop only. The outer loop remains
unaffected.
That means continue skip everything written below and go back to
start of the loop…