About statements 153
When you write complex conditions, it is good form to use parentheses [()] to group
conditions. If you do not use parentheses, you (or others working with your ActionScript)
might run into operator precedence errors. For more information on operator precedence, see
“About operator precedence and associativity” on page 179.
For example, the following code does not use parentheses around the condition:
if (fruit == "apple" && veggie == "leek") {}
The following code uses good form by adding parentheses around conditions:
if ((fruit == "apple") && (veggie == "leek")) {}
Repeating actions using loops
ActionScript can repeat an action a specified number of times or while a specific condition
exists. Loops let you repeat a series of statements when a particular condition is
true. There
are four types of loops in ActionScript:
for loops, for..in loops, while loops, and
do..while loops. Each type of loop behaves somewhat differently, and each one is useful for
different purposes.
Most loops use some kind of counter to control how many times the loop executes. Each
execution of a loop is called an iteration. You can declare a variable and write a statement that
increases or decreases the variable each time the loop executes. In the
for action, the counter
and the statement that increments the counter are part of the action.
Loop Description
for loops Repeat an action using a built-in counter.
for..in loops Iterate over the children of a movie clip or object.
while loops Repeat an action while a condition exists.
do..while loops Similar to while loops, except the expression evaluates at the bottom of
the code block, so the loop always runs at least once.