Commodore 128 System Manual page 309

Hide thumbs Also See for 128:
Table of Contents

Advertisement

EXAMPLE:
10 TRAP 100
20 INPUT " ENTER A NUMBER" ,A
30 B=100/A
40 PRINT"THE RESULT=",B:PRINT"THE END"
50 PRINT" DO YOU WANT TO RUN IT
A G AIN(Y/N)" :GETKEYZ$:IF Z$="Y"THEN 20
60 STOP
100 INPUT" ENTER ANOTHER NUMBER (NOT ZERO)" ;A
110 RESUME
This example traps a "division by zero error" in line 30 if 0 is
entered in line 20. If zero is entered, the program goes to line 100,
where you are asked to input another number besides 0. Line 110
returns to line 30 to complete the calculation. Line 50 asks if you
want to repeat the program again. If you do, press the Y key.
RETURN
Return from subroutine
RETURN
This statement is always paired with the GOSUB statement.
When the program encounters a RETURN statement, it goes to
the statement immediately following the last GOSUB command
executed. If no GOSUB was previously issued, then a RETURN
WITHOUT GOSUB ERROR message is displayed and the
program stops. All subroutines end with a RETURN statement
EXAMPLE
10 PRINT " ENTER SUBROUTINE"
20 GOSUB 100
30 PRINT " END OF SUBROUTINE"
90 STOP
100 PRINT "SUBROUTINE 1"
110 RETURN
This example calls the subroutine at line 100 which prints the
message "SUBROUTINE 1" and RETURNS to line 30, the rest of
the program.
17-67

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

128d

Table of Contents