ON CYCLE defines a repeating event branch (whereas ON DELAY only executes once). After the specified number of seconds has passed, an event is generated and the cycle is started again. The value of seconds can range from 0.01 to 167772.16 but is rounded to the timing resolution of the computer. If short CYCLE values cause events to occur faster than the computer can service them, some events will be lost.
There is only one CYCLE timer. Executing a new ON CYCLE while another ON CYCLE is still in effect will cause the CYCLE timer to use the new seconds value. If ON CYCLE is executed in a different program context, the original ON CYCLE definition (but not the old CYCLE time) is restored when control returns to the calling context.
ON CYCLE is canceled by OFF CYCLE and disabled by DISABLE. It is also canceled after SUBEXIT, SUBEND, or RETURN from the defining subprogram.
The line number or line label following the GOTO, GOSUB or RECOVER or the subprogram name following the CALL indicates where to transfer control when the event occurs. Line numbers or labels must be in the same subprogram as the ON statement. When returning from a CALL or GOSUB execution continues with the line that would have executed next when the event occurred. RECOVER causes the program to SUBEXIT from subprograms as needed to return to the defining subprogram and then does a GOTO to the specified program line. (The defining subprogram is the subprogram with the ON statement.)
The event branch can only occur if the current SYSTEM PRIORITY is less than the priority specified in the ON statement. The default priority is one. The highest priority that can be specified is fifteen. ON END, ON ERROR and ON TIMEOUT events have a higher priority than all other events. If an event branch can not take place because of system priority, the event is logged and occurs later when the system priority drops to a level which allows it.
When an event branch is taken the system priority is changed depending on the branch type. With a GOTO the system priority is not changed. With a RECOVER the system priority is only changed if any SUBEXITs are performed, in which case the system priority is restored to the value when the defining subprogram called another subprogram. With a CALL or GOSUB the system priority is changed to the specified priority. When returning from the CALL or GOSUB the system priority is restored to the value before the branch was taken.
If other subprograms have been called from the defining subprogram when the event occurs, when the branch can be taken depends on the branch type. CALL or RECOVER branches can still occur as soon as the event occurs. (Although branches are not taken in the middle of execution of a line; the branch is taken between lines.) GOTO or GOSUB branches can not be taken immediately. The event will be logged and then serviced when control returns to the defining subprogram.