HTBasic Help
×
Menu
Index

WAIT FOR EVENT Command_2

 
Description
 
WAIT FOR EVENT suspends program execution until a specified event occurs. When an enabled event occurs, WAIT FOR EVENT terminates and the event triggers the appropriate pending ON EVENT statement. If no events are currently defined, WAIT FOR EVENT returns immediately.
 
At the WAIT FOR EVENT statement, program execution is suspended until an event occurs. When an enabled event occurs, the WAIT FOR EVENT statement terminates and the event triggers the appropriate pending ON EVENT statement. If no events are currently defined, WAIT FOR EVENT returns immediately.
 
WAIT FOR EVENT will wait indefinitely for an event unless a TIMEOUT value is specified. The TIMEOUT option specifies the number of seconds after which program execution resumes if no enabled events occur. The corresponding branch may or may not be taken, depending on which context has the highest priority - the current context priority or the defining context priority.
 
_WAIT FOR EVENT will wait if any events are defined, even if any or all events are disabled or are associated with widgets that are not visible. If the widgets are not visible, WAIT FOR EVENT will terminate only if the timeout period is reached, or if you press the Stop or Reset key.
 
For example, the following lines allow the program to loop continuously, waiting for the specified event to occur, which allows the computer to do other things while waiting for the event to occur.
 
     LOOP
         WAIT FOR EVENT
     END LOOP
 
Since the WAIT FOR EVENT statement suspends program execution, the computer is free to service other processes. In the following construct, the computer is "busy waiting" (that is, the CPU stays busy doing nothing):
 
         10   GOTO 10
 
If keeping the CPU free to run other processes is important in your program or computer environment, we recommend using either of the following two constructs:
 
         10   LOOP
         20        WAIT FOR EVENT
         30   END LOOP
 
                         or:
 
         10   WAIT FOR EVENT
         20   GOTO 10