how to break nested for loop python code example
Example 1: how to create a nested loop in python
for i in range(5):
for j in range(i):
# you can add many for loops or you can just write any code
Example 2: how to break out of nested loops python
x_loop_must_break = False
for x in [1, 2, 3]:
print(f"x is {x}")
for y in [1, 2, 3]:
print(f"y is {y}")
if y == 2:
x_loop_must_break = True
break
if x_loop_must_break: break