簡體   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