+ 1

Is there a way to break outer loop with without additional condition checking?

In some programming languages you can name loop(f.e. loop1) and then break it by "break loop1" statement. Does python provide possibility like this?

19th Oct 2016, 11:31 AM
Taron Gevorgyan
Taron Gevorgyan - avatar
1 Resposta
+ 2
well you can't break out of the outer loop using break the method I use is to raise a custom exception eg: class Break1(Exception):pass i=0 j=0 try: while i<9: #this is the outer loop while j<10: #this is inner loop j+=1 if j==5 and i==3: raise Break1 #this will break out of outer loop i+=1 j=0 except Break1: pass print(i,j) for more info: http://stackoverflow.com/questions/189645/how-to-break-out-of-multiple-loops-in-JUMP_LINK__&&__python__&&__JUMP_LINK
19th Oct 2016, 11:47 AM
Sunera
Sunera - avatar