On error goto line number – BrightSign HD2000 BrightScript Reference Guide User Manual

Page 15

Advertising
background image

15

FOR I=10 TO 1 STEP -1

PRINT I;

NEXT


RUN
10 9 8 7 6 5 4 3 2 1


FOR I=1TO3

PRINT"OUTER LOOP"

FOR J=1 TO 2

PRINT" INNER LOOP"

50

NEXT J

60 NEXT

I


RUN

OUTER LOOP
INNER LOOP
INNER LOOP
OUTER LOOP
INNER LOOP
INNER LOOP
OUTER LOOP
INNER LOOP
INNER LOOP

Note that each NEXT statement specifies the appropriate counter variable; however, this is just a
programmer's convenience to help keep track of the nesting order. The counter variable may be omitted from
the NEXT statements. But if you do use the counter variables, you must use them in the right order; i.e., the
counter variable for the innermost loop must come first. It is also advisable to specify the counter variable
with NEXT statements when your program allows branching to program lines outside the FOR-NEXT loop.
Another option with nested NEXT statements is to use a counter variable list.
Delete line 50 from the above program and change line 60:

60 NEXT J,I

ON ERROR GOTO line number

When the Interpreter encounters any kind of error in your program, it normally breaks out of execution and
prints an error message. With ON ERROR GOTO, you can set up an error-trapping routine, which will allow
your program to "recover" from an error and continue, without any break in execution. Normally you have a
particular type of error in mind when you use the ON ERROR GOTO statement. For example, suppose your
program performs some division operations and you have not ruled out the possibility of division by zero.
You might want to write a routine to handle a division-by-zero error, and then use ON ERROR GOTO to
branch to that routine when such an error occurs.

Example:
5 ON ERROR GOTO 100
10 C = 1/0

The error handling routine must be terminated by a RESUME statement. See RESUME.

Advertising
This manual is related to the following products: