August 2024
Intermediate to advanced
256 pages
5h 34m
English
A nested loop is a loop inside another loop. This creates a hierarchical structure where the inner loop is nested within the body of the outer loop. Each iteration of the outer loop triggers a complete set of iterations of the inner loop.
matrix = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
for row in matrix:
for element in row:
print(element, end=’ ‘)
print()
The outer loop iterates over each row in the matrix (2D list). The inner loop iterates over each element in the current row.
Read now
Unlock full access