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.
Also see POP and POPALL.
Example: OPEN (1) "C1A" EXCP=9000 READ (1,1000) EXCP=8000 PRINT (0) "PROCESSING CUSTOMER:";CUSTNO$ GOSUB 1000 PRINT (0) "COMPLETED CUSTOMER:";CUSTNO$ . STOP ! Main routine 1000 CRAVAIL = CRLIMIT - ARTOTAL . . . RETURN
In this example, the main section of the program opens a data file called "C1A", then reads a record from the file in sequential order. Next, the program displays a message on the video terminal (logical unit 0) and branches to a subroutine at statement-label 1000.
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