Nested Loops
Explore the concept of nested loops in JavaScript by learning how outer and inner loops work together to generate combinations and patterns. Understand Cartesian products and practice writing nested loops through coding exercises that include ordered pairs and shapes like squares, rectangles, and triangles.
Nested loop
When we use a loop inside another loop, we call them nested loops. The first loop is called the outer loop, and the second loop is called the inner loop. Nested loops may be the same type or different types of loops. Both loops may be for loops or while loops. The outer loop may be a for loop and the inner loop a while loop, or vice versa.
Let’s use the Cartesian product of two sets to illustrate nested loops.
Cartesian product
The Cartesian product of the sets and is ...