mardi 7 juillet 2020

break command for nested loops inside conditional statement

I want to break main while loop using break statement inside if condition

a = 0
b = True
while b:
    print(a)
    while a < 10:
        if a == 8:
            b = False
            break       # want to break both while loops using this command
        else:
            print(a)
            a += 1

result should be 0 0 1 2 3 4 5 6 7

Aucun commentaire:

Enregistrer un commentaire