back to Command Reference
[All Models]
Jumps to a specified subroutine.
{ branch destination line number }
{ └─────────────┬─────────────┘ }
{ Line number }
GOSUB { }
{ # program area number }
{ └────────┬────────┘ }
{ Single character; 0~9 }
GOSUB 100
GOSUB #6
GOSUB #n form (where n is 0-9) causes execution to branch to the
first line of the specified program area and begin executing there as a subroutine.
When a RETURN is encountered, execution returns to the statement following
the GOSUB #n in the original program area. This allows subroutines to be shared
across program areas.10 REM ***MAIN***
20 GOSUB 40
30 END
40 REM ***SUBROUTINE 1***
50 PRINT "SUBROUTINE 1";
60 GOSUB 80
70 RETURN
80 REM ***SUBROUTINE 2***
90 PRINT "SUBROUTINE 2"
100 RETURN
Line 20 branches to subroutine beginning at line 40, and line 60 branches to subroutine beginning at line 80.