SLEEP: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "SLEEP pauses the program indefinitely or for a specified number of seconds, program is unpaused when the user presses a key or when the specified number of seconds has passed. {{PageSyntax}} :: SLEEP [seconds] * Seconds are an optional INTEGER value. If there is no parameter, then it waits for a keypress. * Any user keypress will abort the SLEEP time. * SLEEP does NOT clear the keyboard buffer so it can affect INKEY$, INPUT, INPUT$ and LINE INPUT...") |
No edit summary |
||
Line 8: | Line 8: | ||
* Seconds are an optional [[INTEGER]] value. If there is no parameter, then it waits for a keypress. | * Seconds are an optional [[INTEGER]] value. If there is no parameter, then it waits for a keypress. | ||
* Any user keypress will abort the SLEEP time. | * Any user keypress will abort the SLEEP time. | ||
* SLEEP does NOT clear the keyboard buffer so it can affect [[INKEY$]], [[INPUT]], [[INPUT$]] and [[LINE INPUT]] reads. | * SLEEP does NOT clear the keyboard buffer so it can affect [[INKEY$]], [[INPUT]], [[INPUT$]] and [[LINE INPUT]] reads. | ||
* Use an [[INKEY$]] keyboard buffer clearing loop when an empty keyboard buffer is necessary. | * Use an [[INKEY$]] keyboard buffer clearing loop when an empty keyboard buffer is necessary. | ||
* SLEEP allows other programs to share the processor time during the interval. | * SLEEP allows other programs to share the processor time during the interval. | ||
Line 14: | Line 14: | ||
''Example:'' | ''Example:'' | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|CLS}} | {{Cl|CLS}} | ||
{{Cl|PRINT}} "Press a key..." | {{Cl|PRINT}} "Press a key..." | ||
{{Cl|SLEEP}} | {{Cl|SLEEP}} | ||
Line 32: | Line 32: | ||
''See also:'' | ''See also:'' | ||
* [[TIMER]], [[INKEY$]] | * [[TIMER]], [[INKEY$]] | ||
* [[_DELAY]], [[_LIMIT]] | * [[_DELAY]], [[_LIMIT]] |
Revision as of 02:40, 23 January 2023
SLEEP pauses the program indefinitely or for a specified number of seconds, program is unpaused when the user presses a key or when the specified number of seconds has passed.
Syntax
- SLEEP [seconds]
- Seconds are an optional INTEGER value. If there is no parameter, then it waits for a keypress.
- Any user keypress will abort the SLEEP time.
- SLEEP does NOT clear the keyboard buffer so it can affect INKEY$, INPUT, INPUT$ and LINE INPUT reads.
- Use an INKEY$ keyboard buffer clearing loop when an empty keyboard buffer is necessary.
- SLEEP allows other programs to share the processor time during the interval.
Example:
CLS PRINT "Press a key..." SLEEP PRINT "You pressed a key, now wait for 2 seconds." SLEEP 2 PRINT "You've waited for 2 seconds." PRINT "(or you pressed a key)" |
Press a key... You pressed a key, now wait for 2 seconds. You've waited for 2 seconds. (or you pressed a key) |
- Explanation: SLEEP without any arguments waits until a key is pressed, next SLEEP statement uses the argument 2 which means that it will wait for 2 seconds, any number of seconds can be specified.
See also: