intel MCS BASIC-52 — Intel MCS BASIC-52 Versions 1 & 1.1 Operating and Reference Manual PDF

int e l 4.12 DESCRIPTION OF STATEMENTS STATEMENTS: GOSUB[ln num] -- RETURN MODE: RUN TYPE: CONTROL GOSUB The GOSUB [In num] STATEMENT will cause MCS BASIC-52 to transfer control of the program directly to the line number ([ln num]) following the GOSUB STATEMENT. In addition, the GOSUB STATEMENT saves the location of the STATEMENT following GOSUB on the control stack so that a RETURN STATEMENT can be performed to return control. RETURN This statement is used to "return" control back to the STATEMENT following the most recently executed GOSUB STATEMENT.

The GOSUB-RETURN sequence can be "nested" meaning that a subroutine called by the GOSUB STATEMENT can call another subroutine with another GOSUB STATEMENT. EXAMPLES: SIMPLE SUBROUTINE NESTED SUBROUTINES >10 FOR I = 1 TO 5 >10 FOR I = 1 TO 3 >20 GOSUB 100 >20 GOSUB 100 >30 NEXT I >30 NEXT I >100 PRINT I >40 END >110 RETURN >100 PRINT I, >RUN >110 GOSUB 200 >120 RETURN 1 >200 PRINT I*I 2 >210 RETURN 3 >RUN 4 5 1 1 2 4 READY 3 9 > READY > - 41 -