Nested Loops

► Overview

Nested loops are loops inside other loops. The inner loop completes all its iterations for each iteration of the outer loop. They’re essential for working with multi-dimensional data like grids, matrices, and tables.

► Real-World Analogy

Think of reading a book:
» Outer loop: For each chapter
» Inner loop: For each page in that chapter
» Result: Read every page of every chapter

► Key Concepts

✓ Inner loop executes completely for each outer loop iteration
✓ Useful for 2D data structures (rows and columns)
✓ Execution time multiplies (outer * inner iterations)
✓ Can nest multiple levels (use carefully)
✓ Common in pattern printing and matrix operations

■ Nested Loop Examples