0% found this document useful (0 votes)
5 views

nested loop

A nested loop is a loop within another loop, allowing for multiple iterations and actions on data. It is commonly used in scenarios such as reading files line by line and counting occurrences of specific words. The document also discusses the advantages of nested loops, including code efficiency and data structure traversal, as well as the behavior of break and continue statements within them.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

nested loop

A nested loop is a loop within another loop, allowing for multiple iterations and actions on data. It is commonly used in scenarios such as reading files line by line and counting occurrences of specific words. The document also discusses the advantages of nested loops, including code efficiency and data structure traversal, as well as the behavior of break and continue statements within them.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

“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…

You might also like