如何停止for循环

如何停止for循环,第1张

如何停止for循环

使用

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
从循环中退出。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5616539.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存