Prev | Current Page 181 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


The for Loop
The for loop in haXe is very different from the for loop used in C and Java, and more closely resembles
the common foreach loop. That is not to say that it is a foreach loop, as it clearly isn ??™ t, but it is similar
insofar as the haXe for loop iterates over objects and values rather than looping until a given expression
returns true .
The haXe for loop is a loop that is directly associated with an iterator object. Iterators will be explained
later in this chapter, and then more deeply in Chapter 5 , ??? Delving Into Object - Oriented Programming, ???
but for the purposes of this explanation, you ??™ ll examine the default iterator: the IntIter object. Before
doing that, though, it ??™ s probably best to explain what an iterator is. An iterator is an object that
represents an iterable value. This can be a list of objects or values such as those contained in an Array, a
numerical value ranging from a given minimum value to a given maximum value, or even the letters of
the alphabet. The iterator will supply the values with the help of two methods that it exposes:
hasNext() and next() .


Pages:
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193