【发布时间】:2015-09-15 02:32:53
【问题描述】:
在 python 中留下循环有 2 种不同的选项。 continue 将您带回到循环的开头,而 break 就像一个电灯开关,它会在脚本运行的剩余时间内切断循环。我的问题是我有一个 while True 循环,我希望能够摆脱它,然后在稍后的代码中返回它。这可能吗,如果可以,我该怎么做?到目前为止,我有这样的事情:
while True
if #condition:
#do something
else:
#do something
break
while True
if #condition:
#do something
else:
break
#code that returns it to the first loop
有没有办法做到这一点,比如 unbreak 之类的?抱歉,我是编程新手,这是我在计算机科学专业的第一年,我刚刚开始学习 python。
【问题讨论】:
标签: python loops python-3.x