Answers for "python break out of multiple loops"

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 out of 2 loops python

breaker = False #our mighty loop exiter!
while True:
    while True:
        if conditionMet:
            #insert code here...
            breaker = True 
            break
    if breaker: # the interesting part!
        break   # <--- !
Posted by: Guest on May-06-2021

Code answers related to "python break out of multiple loops"

Python Answers by Framework

Browse Popular Code Answers by Language