How to break the outer loop in Python

2 Answers

0 votes
found = False
for i in range(6):
    print("i)", i)
    for j in range(3):
        print("j)", j, end=" ")
        if i == 3:
            found = True
            break
    print()
    if found:
        break



'''
run:

i) 0
j) 0 j) 1 j) 2 
i) 1
j) 0 j) 1 j) 2 
i) 2
j) 0 j) 1 j) 2 
i) 3
j) 0 

'''

 



answered Apr 29 by avibootz
0 votes
def break_outer_loop():
    for i in range(6):
        print("i)", i)
        for j in range(3):
            print("j)", j, end=" ")
            if i == 3:
                return
        print()            
            
break_outer_loop()



'''
run:

i) 0
j) 0 j) 1 j) 2 
i) 1
j) 0 j) 1 j) 2 
i) 2
j) 0 j) 1 j) 2 
i) 3
j) 0 

'''

 



answered Apr 29 by avibootz

Related questions

3 answers 63 views
1 answer 37 views
1 answer 37 views
1 answer 49 views
1 answer 45 views
...