beautypg.com

For each item in object – BrightSign BrightScript 2 Reference Guide User Manual

Page 26

background image

26

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.

When program flow reaches the NEXT statement, 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.

.Example:

for i=10 to 1 step -1

print i

next

Note that each NEXT statement optionally 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.

The counter variable must be “simple”; eg, not an array.

“EXIT FOR” is used to exit a FOR block prematurely.

FOR EACH item IN object

The FOR EACH statement iterates through each item in any object that has an “ifEnum”
interface (enumerator). The For block is terminated with a NEXT statement. The
variable item is set at the top of the loop to the next item in the object. Objects that are
intrinsically ordered (like a List) are enumerated in order. Objects that have no intrinsic
order (like AssociativeArray) are enumerated in apparent random order. It is okay to
delete entries as you enumerate them.

“EXIT FOR” is used to exit a FOR block prematurely.

The following example objects can be enumerated: roList, roArray, roAsscoiativeArray,
roMessagePort.

Example:
**NOTE: this example does not yet work because literal arrays are not yet
implemented**

aa={joe: 10, fred: 11, sue:9}
For each n in ar
Print n;aa(n)
aa.delete(n)
next