GOSUB causes execution to jump to a Basic subroutine located elsewhere in the applications program.
GOSUB line number
GOSUB numeric expression
causes program execution to jump to a subroutine located at 150.
The argument can also be an argument or expression, for example:
This is illustrated by the program sequence:
10 INPUT A 20 SI=1000 30 GOSUB SI+100*A 40 STOP 1000 PRINT "THIS IS SUBROUTINE 1" 1010 RETURN 1100 PRINT "THIS IS SUBROUTINE 2" 1110 RETURN etc.
If the number 0 is entered in line 10, the program will perform subroutine 1. Input of the number 1 will cause subroutine 2 to be executed.
A subroutine must always be terminated by a RETURN statement. Program execution then continues from the statement immediately after the GOSUB. GOSUB always requires a line number as an argument.