A nested loop is a loop inside a loop. This is really useful in programming but can often seem a little confusing. Let’s try to simplify some examples 👇

Look at the below nested for loop

for i in range(1,4):
		for j in range(1,4):
				print(f"{i}:{j}")

I will colour code this for simplicity. In the example above there is an outer loop and an inner loop.

So for i amount of times, the range of j will be displayed. The output should be:

1:1

1:2

1:3

2:1

2:2

2:3

3:1

3:2

3:3

See if you can visualise this using this Python-Tutor example

https://youtube.com/shorts/JbcMsNBfDig?si=kFJpSLxLu82MZn9g

Tasks: