Game Development Reference
If you opened the bknHkkl project, experiment with a few different values and conditional statements
and see what the output looks like when you test it. You can initialize e to any number you like, and
use any condition to quit the loop. Here's another example: e is initialized to -, and the loop repeats
until it becomes 1:
This produces the following output:
Initializing the index variable to 1 and quitting the loop on 5 is particularly useful because it makes it
very clear where the loop starts and ends.
You'll look at a few different ways to use bkn loops over the course of this chapter. Figure 9-15 is
a quick-reference diagram of the way bkn loops work.
The for keyword tells
AS3.0 that you're
creating a loop.
Declare and initialize the index variable,
usually i. The number that it's initialized to
is the number at which the loop will start.
The loop will run any
directives it contains while
this condition is true.
Each time the loop repeats,
1 is added to the value of
the index variable.
Whenever the index variable, i, is used in any of the loop's
directives, it is replaced by whatever its current value is.
This loop will produce the following in the
Figure 9-15. The for loop in detail