我正在用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
立即转到下一个循环迭代还有。。。如果您只是想跳出else语句,我不知道您为什么这么做,因为在这行下面没有任何代码
尝试使用continue语句https://www.tutorialspoint.com/python/python_loop_control.htm#:~:text=The%20continue%20statement%20in%20Python,both%20while%20and%20for%20loops
相关问题 更多 >
编程相关推荐