Answer the question
In order to leave comments, you need to log in
How to make a loop that repeats every second?
How to make a loop that repeats every second?
Answer the question
In order to leave comments, you need to log in
while(true){ // запускаем бесконечный цикл
sleep(1); // задержка в 1 секунду
}
just do not forget that the cycle + sleep(1) in one hour will be executed not 3600 times, but less, since the cycle time will take 1 sec + the time for performing operations in the cycle.
For some tasks, this is not critical, but for example, programming microcontrollers (I encountered this) is quite critical.
And we must not forget that if you work with peripherals (serial ports, usb, requests to external web servers), the operation time is relatively large.
In this case, one could contrive to track the execution time of operations in a loop (microtime in php for example) and subtract this time from a second, or even bind to the server clock (to be honest, I did this only in c # and then as an experiment)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question