The SLEEP command is used to introduce small delays in your program. The argument is an integer which specifies the
number of milliseconds the program should wait for. If the argument is zero, or negative, then the SLEEP command causes
the program to briefly yield the processor to allow other tasks to run. If there are no other tasks waiting then the
BASIC program resumes immediately.
Using “SLEEP 1” is much more friendly to the phone. It allows other tasks to run more readily and greatly reduces the
amount of CPU processing power consumed. For example, lets say that your phone processor can process 10 million
instructions a second. It will only take the processor a small number of instructions to work out if an event has
occured (e.g. screen touched) - lets say its 100 instructions for sake of an example. This would result in the loop
being executed 100000 times a second. Is this necessary? Do you need to detect for the event again immediately again
(i.e. within 1/100000 second)? Probably not! “SLEEP 1” puts the program to SLEEP for 1/1000 second before it resumes and
checks again. The result is that the program will check for the event button 1000 times a second using 100 instructions
each time. The total number of instructions executed would be 100*1000 = 100000 which is 1% of the available processing
time. The remaining 99% of the processor time is now idle which may reduce power consumption as well as giving the screen
more chance to update.
DIM I AS INTEGER
FOR I=1 TO 10