C++20 sections · 1024 units
Open in Course

Nested Loop Patterns

Common use cases

Nested loops generate grids, tables, and combinations. Outer loop picks rows, inner loop picks columns. You get every (row, column) pair. Printing a multiplication table uses nested loops: for (int i = 1; i <= 10; i++) { for (int j = 1; j <= 10; j++) { cout << i*j; } }.

Break and continue affect only the innermost loop. Breaking from the inner loop exits the inner loop but continues the outer loop.