繁体   English   中英

跳出 if else 循环而不跳出 while 循环

[英]Break out of if else loop without breaking out of while loop

我正在 Python 中制作一个程序,我需要在不跳出 while 循环的情况下跳出 if else lop。

当前代码(例如,不完整的代码。不是完整的代码。):

class foo:
  def __init__(self, time1, link)
        while self.isItNow == False:
            self.current_time = self.now.strftime("%H:%M")
            print(self.current_time)
            if str(self.current_time) == self.time1:
                webbrowser.open(self.link, new=1)
                self.isItNow = True
            else:
                print("Current Time =", self.current_time,". Retrying again in 5 seconds")
                time.sleep(5)
                break

我想打破 else 并再次启动 if 循环,但我不能这样做,因为它打破了 while 循环。

提前致谢!!!!

Else 不是循环,但您可以使用continue立即 go 到下一个循环迭代。

另外...如果您只想跳出 else 语句,我不确定您为什么要这样做,因为该行下方没有任何代码...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM