Interrupt routines

Interrupt routines in RFO-BASIC! let a program break out of a strict sequence of operations. At the end of the execution of a BASIC statement, if certain events occur in the outside world (such as the pressing of a key), BASIC checks to see if the program has an interrupt routine to handle that event. If so, BASIC remembers where it was and effectively performs a GOSUB to that interrupt routine. The routine takes action in response to the event and then, by executing a return statement that matches the event that occurred, returns to the point in the program that was interrupted.

An interrupt routine consists of the code starting with a built-in label, through the matching return statement, such as:

OnBackKey:  ONBACKKEY.RTN

Interrupt routines are not ordinary GOSUB subroutines. If you do not use the designated return statement to return to the interrupted code, but use RETURN, then you have not officially exited the interrupt routine. This typically means the program will not be interrupted again if the same type of event should occur again. Generally, interrupt routines should set a variable for the main program to sense, rather than perform extensive or time-consuming operations such as request user input.

BASIC Interrupts do not correspond to hardware interrupts in the Android device. They do not actually interrupt the execution of a BASIC statement. The BASIC interpreter checks for a variety of external events after executing each statement.

Notably, an interrupt cannot curtail the execution of the PAUSE statement. If a program's next scheduled activity is in 5 seconds, a BASIC programmer may write a loop to PAUSE for 100 msec up to fifty times, so that the program is more responsive to events such as keystrokes. Unfortunately, resuming from PAUSE, in case the program will be interrupted, increases the use of the device's battery.