GOSUB
n
n
GOTO/GOTO
—Call a subroutine from the specified line number
GOSUB line number
This statement is similar to the GOTO statement, except the Commo
dore 128 returns from where it came when the subroutine is finished.
When a line with a RETURN statement is encountered, the program
jumps back to the statement immediately following the GOSUB
statement.
The target of a GOSUB statement is called a subroutine. A subrou
tine is useful if a task is repeated several times within a program.
Instead of duplicating the section of program over and over, set up a
subroutine, and GOSUB to it at the appropriate time in the program.
See also the RETURN statement.
EXAMPLE:
20 GOSUB 800
This example calls the subroutine beginning at
line 800 and executes it. All subroutines must
terminate with a RETURN statement.
800 PRINT "HI THERE": RETURN
—Transfer program execution to the specified line number
GOTO line number
After a GOTO statement is encountered in a program, the computer
executes the statement specified by the line number in the GOTO
statement. When used in direct mode, GOTO executes (RUNs) the
program starting at the specified line number wi thout clearing the
variables.
EXAMPLES:
10 PRINT"COMMODORE" The GOTO in line 20 makes line 10
20 GOTO 10
repeat continuously until RUN/STOP is
pressed.
GOTO 100
Starts (RUNs) the program starting at
line 100, without clearing the variable
storage area.
269
BASIC 7.0 ENCYCLOPEDIA—Basic Commands and Statements
Need help?
Do you have a question about the 128D and is the answer not in the manual?