How to break out of nested loops python


Topic: How to break out of nested loops python

Solution

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
my_list = ['apple pie', 'orange jam']
my_list[0].capitalize()



List all Python Programs