mardi 15 juin 2021

Break out of if else loop without breaking out of while loop

I was making an program in Python and I needed to break out of if else lop without breaking out of while loop.

Current code (incomplete code just for example. Not full code.):

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

I wanted to break the else and start the if loop again but I can't do it because it breaks out of the while loop.

Thanks in advance!!!!

Aucun commentaire:

Enregistrer un commentaire