37
ERROR Statement
Purpose:
To simulate the occurrence of an error, or to allow error codes to
be defined by the user
Format:
ERROR <n>
<n> is the error code to be simulated.
Remarks:
Error code numbers 1 to 255 are predefined and reserved by BASIC. Higher
numbers can be used for user-defined error code messages. User-defined error
codes can be used together with the ON ERROR GOTO statement to branch the
program to an error handling routine.
When the ERROR statement is executed without an accompanying ON ERROR
GOTO statement, the error message corresponding to the specified error num-
ber is output and program execution is stopped. The message UNDEFINED ER-
ROR is displayed if an undefined error occurs.
The error number is assigned to the variable ERR and the line number where the
error occurred is assigned to the variable ERL.
FOR and NEXT Statements
Purpose:
To allow a series of instructions to be performed in a loop a given
number of times
Format:
For <var>=<x> TO <y> [STEP<z>]
<x>, <y>, and <z> are numeric expressions.
Example:
100 FOR Y = base TO 10 STEP 2
110 NEXT Y
Remarks:
<var> is used as a counter. The first numeric expression (<x>) is the initial value
of the counter. The second numeric expression (<y>) is the final value of the
counter.
The program lines following the FOR statement are executed until the NEXT
statement is encountered. Then the counter is incremented by the amount spe-
cified by STEP.
A check is performed to see if the value of the counter is now greater than the
final value (<y>). If it is not greater, execution branches back to the first state-
ment after the FOR statement and the process is repeated. If it is greater, execu-
tion continues with the statement following the NEXT statement. This is a
FOR...NEXT loop.
If STEP is not specified, the increment is assumed to be one. If STEP is negative,
the counter will count down instead of up. In this case, the loop will be executed
until the counter is less than the final value.
The body of the loop will never be executed if the initial value of the loop is great-
er than the final value.
NESTED LOOPS
FOR...NEXT loops may be nested, that is, a loop can be placed inside of another
loop. When loops are nested, each loop must have a unique variable name for its
counter. The NEXT statement for the inside loop must come before the NEXT
statement for the outer loop.
If nested loops have the same end point, the same NEXT statement can be used
for both of them.
If a NEXT statement is encountered before its corresponding FOR statement,
an error message is issued and execution is terminated.
Commands, Statements, and Functions
Summary of Contents for C500-ASC04
Page 1: ...C500 ASC04 ASCII Unit Operation Manual Revised February 2001 ...
Page 5: ...iv ...
Page 7: ...vi ...