For each in / end for – BrightSign BrightScript 3.0 Reference Manual User Manual

Page 44

Advertising
background image

39


When program flow reaches the

END FOR statement, the counter is incremented by the specified increment amount (or

decremented if

increment is a negative value). If the STEP [increment] language is not included in the FOR

statement, the

increment defaults to 1.


Use

EXIT FOR to exit a FOR block prematurely.


Example: The following script decrements

i at the beginning of each loop until it is less than 1.

for i=10 to 1 step -1

print i

end for

FOR EACH IN / END FOR

FOR EACH item IN object / END FOR


The

FOR EACH statement can iterate through a set of items in any object that has an ifEnum interface (i.e. an

enumerator). The

FOR block is terminated with the END FOR statement. Objects that are ordered intrinsically (such as

roList) are enumerated in order, while objects that have no intrinsic order (such as roAssociativeArray) are enumerated in
apparent random order. It is possible to delete entries as they are enumerated.

Use

EXIT FOR to exit a FOR block prematurely.


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

Example: The following script iterates over an associative array in random order, prints each key/value pair, then deletes
it.
aa={joe: 10, fred: 11, sue:9}

Advertising