Python提早退出循环 [英] Python Leave Loop Early
本文介绍了Python提早退出循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在python早期退出循环?
How do I leave a loop early in python?
for a in b:
if criteria in list1:
print "oh no"
#Force loop i.e. force next iteration without going on
someList.append(a)
此外,在Java中,您可以循环break
,Python中是否有等效功能?
Also, in java you can break
out of a loop, is there an equivalent in Python?
推荐答案
continue
和break
是您想要的.在这方面,Python的工作方式与Java/C ++相同.
continue
and break
is what you want. Python works identically to Java/C++ in this regard.
这篇关于Python提早退出循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文