Search⌘ K
AI Features

Nested Loops

Explore how nested loops work in C++ by studying examples such as Cartesian products and various shape patterns. Understand the structure of outer and inner loops, and apply this knowledge to solve programming challenges involving ordered pairs and shapes.

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 as an illustration of nested loops.

Cartesian product

The Cartesian product of the sets A={1,2,3}A = \{-1,-2,-3\} and B={1,2,3}B = \{1,2,3\} is A× ...