Answers for "how to break outer loop in python"

1

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
Posted by: Guest on August-23-2020
0

break while loop python

1n = 5
 2while n > 0:
 3    n -= 1
 4    if n == 2:
 5        break
 6    print(n)
 7print('Loop ended.')
Posted by: Guest on April-18-2021

Code answers related to "how to break outer loop in python"

Python Answers by Framework

Browse Popular Code Answers by Language