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 to occur unless you use the TIMEOUT option with it. The TIMEOUT option specifies the number of seconds after which program execution resumes if no event has occurred.
The corresponding branch may or may not be taken, depending which has the highest priority: the current context and its priority or the defining context and its priority.
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):
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
WAIT FOR EVENT
GOTO 10
NOTE
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 keys.