+ 1

Repeat while loop

How to repeat a while loop scope infinit time for an amount of time. for example loop through 5 to 0 for 1 hour. over and over again

14th Aug 2018, 9:38 AM
Iman Rafi
Iman Rafi - avatar
4 Answers
+ 11
So, what you're basically asking is how to have a process executed for a specific amount of time?
14th Aug 2018, 10:34 AM
Fox
Fox - avatar
+ 4
This version runs for a second, change x to 3600 if you want it to run for an hour: import time # use x = 3600 if you want to run it for an hour, it may overheat your computer x = 1 # make it run for x seconds y = time.time() + x z = time.time() while z < y: z = time.time() for u in range(5, -1, -1): print(u, end = ' ') print ("")
14th Aug 2018, 1:13 PM
Paul
Paul - avatar
+ 3
This will run until the end of the hour (Or time limit exceded): import time y = int(time.strftime("%H")) x = y while y == x: y = int(time.strftime("%H")) print(y) I got time limit exceeded.
14th Aug 2018, 10:14 AM
Paul
Paul - avatar
+ 1
Let me ask import time while True: def fivetozero(): i = 1 while i <= 5: print(i) i = i + 1 time.sleep(2) #loop every2s print("finished") fivetozero() it goes forever... how to make a stop time for this code or in other words.. make fivetozero() func stop
14th Aug 2018, 12:51 PM
Iman Rafi
Iman Rafi - avatar