EasyManua.ls Logo

Commodore 128 - Page 309

Commodore 128
448 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
EXAMPLE:
10 TRAP 100
20 INPUT ENTER A NUMBER,A
30 B=100/A
40 PRINTTHE RESULT=,B:PRINTTHE END
50 PRINTDO YOU WANT TO RUN IT
AGAIN(Y/N):GETKEYZ$:IF Z$=YTHEN 20
60 STOP
100 INPUTENTER 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

Table of Contents

Other manuals for Commodore 128

Related product manuals