
How to make a nested for loop in Python
In this lesson I'll explain how to make a nested for loop in Python by a practical example.
What is a nested loop? It is simply an inner loop inside another outer loop.
Example
This script uses a simple nested loop
How does it work?
The outer loop prints the rows while the inner loop prints the columns.
- In each iteration of the outer loop (row), the program goes through a complete inner loop.
- In each iteration of the inner loop (column), the program prints the product between the row and the current column.
Here is the program output
If you like this lesson, keep following us.