The NEXT statement is used with the FOR statement. When the
computer encounters a NEXT statement, It goes back to the
corresponding FOR statement and checks the loop variable. (See FOR
statement for more detail.) If the loop is finished. execution proceeds
with the statement after the NEXT statement. The word NEXT may be
followed by a variable name. a list of variable names separated by
commas, or no variable names. It there are no names listed. the last
loop started is the one being completed. If the variables are given, they
are completed in order from left to right.
EXAMPLE -
10 INPUT X:IF X < 0 THEN
10
20 ON X GOTO 50, 30, 30, 70
25 PRINT "FELL THROUGH":GOTO 10
30 PRINT "TOO HIGH":GOTO 10
50 PRINT"TOO LOW":GOTO 10
70 END
When X = 1. ON
sends control to the
first line number in the
list (50). When X = 2,
ON sends control to
the second line (30),
etc.
{
V
I
I
f
1
f I
(
I
I
I
f
f
I
I
, f
I
f
'
'
r
r
I
f
EXAMPLE:
10
FOR L = 1 TO 10:NEXT
20 FOR L = 1 TO 10:NEXT L
30 FOR L= 1 TO 10:FOR M = 1 TO 10: NEXT M, L
ON
ON expression <- GOTO/GOSUB> line Al I, fine #2,
. ]
This command can make the GOTO and GOSUB statements into
special versions of the IF statement The word ON is followed by a
formula, then either GOTO or GOSUB. and a list of line numbers
separated by commas. If the result of the calculation of the formula
(expression) is 1, the first line in the list is executed. If the result is 2.
the second line number is executed, and so on. If the result is 0, or
larger than the number of ;ine numbers in the fist. the next line executed
is the statement following the ON statements. If the number is negative.
an ILLEGAL QUANTITY ERROR results.
OPEN
OPEN file # (.device #1.secondary address rfilename, type, mode' .111
The OPEN statement allows your Commodore 16 lo access devices
such as the Datassette recorder and disk for data, a printer, or even the
monitor screen. The word OPEN is followed by a logical file number.
which is the number to which all other BASIC statements will refer. This
number is from Ito 255. There is normally a second number after the
first called the device number. Device number 0 is the Commodore 16
keyboard. 3 Is the screen, 1 is the Datassette recorder (default), 4 Is the
printer. 8 is usually the disk. A zero (0) may be included in front of the
device number digit (e.g . 08 for 8. which are interchangeable as far as
your Commodore 16 is concerned). It Is often a good idea to use the
same file number as the device number because it makes it easy to
remember which is which. Following the second number may be a
third number called the secondary address. In the case of tne cassette,
this can be 0 for read. 1 lw write, and 2 for write with end-of-tape
marker at the end. In the case of the disk, the number refers to the
channel number. In the printer, the secondary addresses are used to
set the mode of the printer. See the Commodore 16 Programmer's
Reference Manual or the manual for each specific device for more
information on secondary addresses. There may also be a string
following the third number, which could be a command to the disk
drive or the name of the file on tape or disk. The type and mode refer
126
127
Need help?
Do you have a question about the Commodore 16 and is the answer not in the manual?
Questions and answers