使用
break和
continue为此。可以使用以下命令在Python中完成打破嵌套循环的 *** 作:
for a in range(...): for b in range(..): if some condition: # break the inner loop break else: # will be called if the previous loop did not end with a `break` continue # but here we end up right after breaking the inner loop, so we can # simply break the outer loop as well break
另一种方法是将所有内容包装在函数中,并用于
return从循环中退出。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)