Introduction | Language Structure | IB Statements | File System | Comet 32 Runtime | Index |
| Syntax: | RETURN | ||||
| Discussion: |
The RETURN statement transfers program control to the statement
immediately following the most recently invoked subroutine call.
Subroutines are most commonly called with the GOSUB statement, although they may also be invoked with the ERRORSUB, ESCAPESUB, and MESSAGESUB statements, as well as the EXCPSUB= parameter. All subroutine calls in Internet Basic place a "return address" in a subroutine stack. The RETURN statement simply transfers program control to the address on the top of this stack. It also removes or "pops" the address from the top of the stack so that a subsequent RETURN statement will use the next address it finds on the top of the stack. Executing a RETURN statement with no return address in the subroutines stack causes a "GOSUB STACK UNDERFLOW" exception condition. | ||||
| Example: |
Processing continues in the subroutine until the program encounters the RETURN statement. At this point, control is transferred back to the main section of the program (to the statement immediately after the GOSUB 1000 statement). The STOP statement is included in the main section of the program to prevent program flow from entering the subroutine without using the GOSUB statement. | ||||