Chapter
10
I
BASIC Keywords
Example
10 COM(1)
ON
200 ON COM(1
1
GOSUB 1000
Line 10 turns on communication trapping on Channel 1. After
each program statement is executed, BASIC checks
to
see if the
communication buffer contains characters. If it does, BASIC im-
mediately executes the subroutine beginning at Line 1000.
10 COM(1)
ON
20 ON COMC1) GOSUB 1000
30 FOR
I
=
1
TO
10
40 PRINT
I
50 NEXT
I
1000
’
SUBROUTINE CODE
1050 RETURN 200
If activity occurs on Communication Channel
1
while the FOR/
NEXT loop
is
executing, BASIC immediately executes the sub-
routine beginning
at
Line 1000. But the subroutine returns
to
Line 200 instead
of
completing the FORiNEXT loop. This results
in a “For without next” error because any GOSUB, FOR,
or
WHILE statement remains active during key trapping.
If
the RETURN statement does not include a line number, pro-
gram control returns to complete the FOR/NEXT loop, and no
error occurs.
227