#python直接退出多重循环的方法
#方法1,抛出异常
class getoutofloop(Exception): pass
try:
for i in range(5):
for j in range(5):
for k in range(5):
if i == j == k == 3:
raise getoutofloop()
else:
print (i,'----', j,'----', k)
except getoutofloop:
pass
print("done")
#方法2,函数中return
def test():
for i in range(5):
for j in range(5):
for k in range(5):
if i == j == k == 3:
return
else:
print (i, '----', j, '----', k)
test()
#方法3,利用for-else、continue和break
for i in range(5):
for j in range(5):
for k in range(5):
if i == j == k == 3:
break
else:
print (i, '----', j, '----', k)
else: continue
break
else: continue
break