Therefore, in your example, the loop would write the values 0
to 9 on the screen.
When supplying the variable to the left - hand side of the in keyword in a for loop statement, you do not
include the var declarator, as the variable will be declared for you.
The IntIter Operator
The IntIter iterator is quite special when compared to other iterator types, as one can be declared and
instantiated automatically using the iterator operator ( ... ). Using this operator, you can rewrite the
previous example like this:
for ( i in 0...10 )
trace( i );
The IntIter iterator cannot operate in a decrementing fashion, so counting backward from 10 to 0 is not
possible. However, you can imitate this process using a trick, by deducting one more than the value of
the current iteration from the maximum value:
for ( i in 0...10 )
trace( 10 - ( i + 1 ) );
Looping Over Collections
Most applications that use Array s and List s will likely want to loop through the contained values at
some point. In fact, the List has been highly customized to this end and would be pretty useless
without some form of iteration being applied to its content.
Pages:
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196