SLEEP(n)

[<<<] [>>>]

Suspend the execution of the interpreter (process or thread) for n seconds.

Whenever the program has to wait for a few seconds it is a good idea to call this function. Older BASIC programs originally designed for old personal computers like Atari, Amiga, ZX Spectrum intend to use empty loop to wait time to elapse. On modern computers this is a bad idea and should not be done.

If you execute an empty loop to wait you consume CPU. Because the program does not access any resource to wait for it actually consumes all the CPU time slots that are available. This means that the computer slows down, does not respond to user actions timely.

Different computers run with different speed and an empty loop consuming 20sec on one machine may run 2 minutes on the other or just 10 millisec. You can not reliably tell how much time there will be during the empty loop runs.

When you call SLEEP(n) the operating system is called telling it that the code does not need the CPU for n seconds. During this time the program is suspended and the operating system executes other programs as needed. The code is guaranteed to return from the function SLEEP not sooner than n seconds, but usually it does return before the second n+1 starts.


[<<<] [>>>]