GOSUB – RETURN

The GOSUB-RETURN control structure enables the creation of subroutines. The subroutine is started with the GOSUB control command. The RETURN control command is used to return to the main program.

The syntax is

GOSUB line number
… instructions …
RETURN

Example

FOR I = 1 TO 10 STEP 1
GOSUB 1000
PRINT I, S
NEXT
PRINT "DONE"
END
REM SUBROUTINE
1000 A = 1
S = ""
FOR J = 1 TO A STEP 1
S = S + "#"
NEXT
RETURN