
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
148
|
Chapter 6: Statements
Loops and Conditionals
We’ve already had several informal encounters with loops and conditionals.
Together, these two statement types account for the majority of complex flow in our
programs. Loops allow us to execute statement blocks repeatedly, and conditionals
allow us to execute statement blocks under only the specified circumstances. See
Chapters 7 and 8 for complete details.
Expression Statements
Although any expression can be used independently as a valid statement, if the
expression performs no action and we don’t do anything with the result, the exercise
is rather pointless:
"hi there"; // This doesn't do much
345 + 5; // Neither does this
Some expressions, however, have side effects that change the state of a system
through variable or property assignments or by physically altering the Flash environ-
ment. In this example, an expression changes the value of
x:
x = 345 + 5; // Much more useful
if-else if-else
if (expression) {
statements
} else if (expression) {
statements
} else {
statements
}
Executes one or more statements, based on a condi-
tion or a series of conditions
ifFrameLoaded
ifFrameLoaded (frame) {
statements
}
Executes specified code if a certain frame has loaded;
deprecated as of Flash 5
return
return;
return expression;
Exits and optionally returns a value ...