Python Code Example: double nested for-loop

This code defines a nested loop structure with three levels: an outer loop, a middle loop, and an inner loop.

The outer loop (for i in range(3, 5)) will run twice, with i taking on the values 3 and 4.

For each iteration of the outer loop, the middle loop (for j in range(1, 10)) will run 9 times, with j taking on the values 1 through 9.

For each iteration of the middle loop, the inner loop (for k in range(1, 5)) will run 4 times, with k taking on the values 1 through 4.

At each iteration of the inner loop, the code will print the product of i, j, and k (separated by a space), using print(i * j * k, end=" "). After each iteration of the inner loop, a newline character (\n) is printed to create a blank line (print()).

After each iteration of the middle loop, another newline character is printed, creating a blank line (print()). This separates the products of each iteration of the middle loop.

After each iteration of the outer loop, another newline character is printed, creating a blank line. This separates the products of each iteration of the outer loop.

So, the code will print a series of products, separated by spaces, with blank lines separating the products of each iteration of the middle loop and the outer loop.

for i in range(3, 5):
    for j in range(1, 10):
        for k in range(1, 5):
            print(i * j * k, end=" ")
        print()
    print()
Output
3 6 9 12 
6 12 18 24 
9 18 27 36 
12 24 36 48 
15 30 45 60 
18 36 54 72 
21 42 63 84 
24 48 72 96 
27 54 81 108 

4 8 12 16 
8 16 24 32 
12 24 36 48 
16 32 48 64 
20 40 60 80 
24 48 72 96 
28 56 84 112 
32 64 96 128 
36 72 108 144