Chapter
10
I
BASIC
Kevwords
ERROR
Statement
ERROR
code
Simulates
a
specified error during program execution.
Code
is an integer expression in the range
0
to
255
specifying
one
of
BASIC's
error codes.
This statement
is
used mainly for testing an ON
ERROR
GOTO
routine. When the computer encounters an
ERROR
statement, it
proceeds as if the error corresponding
to
that code has occurred.
(Refer
to
Chapter
12
for a listing
of
error codes and their
meanings.)
Example
ERROR 1
causes a "NEXT without
FOR"
error (Code
1)
when
BASIC
reaches this line.
Sample Program
110 ON ERROR GOTO
400
120 INPUT "WHAT IS YOUR BET";
B
130 IF
B>5000
THEN ERROR 21 ELSE GOTO 420
400 IF ERR
=
21 THEN PRINT "HOUSE LIMIT
IS
$5
0 0
0"
410 IF ERL
=
130
THEN RESUME
500
420
S
=
S+B
430 GOTO 120
500
PRINT "THE TOTAL AMOUNT OF YOUR BET 1S";S
510 END
This program receives and totals bets until one of them exceeds
the house limit.
157