BrightSign HD2000 BrightScript Reference Guide User Manual

Page 14

Advertising
background image

14

RETURN
PRINT "ERROR!":STOP
queen:
PRINT "queen!"

RETURN

Ends a subroutine and returns control to the statement immediately following the most recently executed
GOSUB.

ON n GOTO line number or label, …, line number or label or
run-time variable

This is a multi-way branching statement that is controlled by a test variable or expression. The general format
for ON n GOTO is:

ON expression GOTO 1st line number, 2nd line number, …, Kth line number

When ON … GOTO is executed, first the expression is evaluated and the integer portion … INT(expression)
… is obtained. We'll refer to this integer portion as J. The Computer counts over to the Jth element in the
line-number list, and then branches to the line number specified by that element. If there is no Jth element
(that is, if J > K or J=0 in the general format above), then control passes to the next statement in the program.
If the test expression or number is less than zero, or greater than 255, an error will occur. The line-number list
may contain any number of items. For example:

ON MI GOTO 150, 160, 170, 150, 180
ON MI GOTO LABEL1, LABEL2, LABEL3, LABEL4, LABEL5

FOR counter = exp TO exp STEP exp NEXT counter

Opens an iterative (repetitive) loop so that a sequence of program statements may be executed over and over
a specified number of times. The general form is (brackets indicate optional material):

line # FOR counter-variable = initial value TO final value [STEP increment]
. .[program statements]
. line # NEXT [counter-variable]

In the FOR statement, initial value, final value and increment can be constants, variables or expressions. The
first time the FOR statement is executed, these three are evaluated and the values are saved; if the variables
are changed by the loop, it will have no effect on the loop's operation. However, the counter variable must not
be changed or the loop will not operate normally.

The FOR-NEXT-STEP loop works as follows: the first time the FOR statement is executed, the counter is set
to the "initial value." Execution proceeds until a NEXT statement is encountered. At this point, the counter is
incremented by the amount specified in the STEP increment. (If the increment has a negative value, then the
counter is actually decremented.) If STEP increment is not used, an increment of 1 is assumed.

Then the counter is compared with the final value specified in the FOR statement. If the counter is greater
than the final value, the loop is completed and execution continues with the statement following the NEXT
statement. (If increment was a negative number, loop ends when counter is less than final value.) If the
counter has not yet exceeded the final value, control passes to the first statement after the FOR statement.

Example Programs:

Advertising
This manual is related to the following products: