do while
145
do while
Availability
Flash Player 4.
Usage
do {
statement(s)
} while (
condition
)
Parameters
condition
The condition to evaluate.
statement(s)
The statement(s) to execute as long as the
condition
parameter evaluates
to
true
.
Returns
Nothing.
Description
Statement; similar to a
while
loop, except that the statements are executed once before the initial
evaluation of the condition. Subsequently, the statements are executed only if the condition
evaluates to
true
.
A
do..while
loop ensures that the code inside the loop executes at least once. Although this can
also be done with a
while
loop by placing a copy of the statements to be executed before the
while
loop begins, many programmers believe that
do..while
loops are easier to read.
If the condition always evaluates to
true
, the
do..while
loop is infinite. If you enter an infinite
loop, you encounter problems with Flash Player and eventually get a warning message or crash the
player. Whenever possible, you should use a
for
loop if you know the number of times you want
to loop. Although
for
loops are easy to read and debug, they cannot replace
do..while
loops in
all circumstances.
Example
The following example uses a
do..while
loop to evaluate whether a condition is
true,
and
traces
myVar
until
myVar
is greater than 5. When
myVar
is greater than 5, the loop ends.
var myVar:Number = 0;
do {
trace(myVar);
myVar++;
} while (myVar<5);
/* output:
0
1
2
3
4
*/
CHAPTER 5
ActionScript Core Language Elements
Summary of Contents for FLEX-FLEX ACTIONSCRIPT LANGUAGE
Page 1: ...Flex ActionScript Language Reference...
Page 8: ......
Page 66: ...66 Chapter 2 Creating Custom Classes with ActionScript 2 0...
Page 76: ......
Page 133: ...break 133 See also for for in do while while switch case continue throw try catch finally...
Page 135: ...case 135 See also break default strict equality switch...
Page 146: ...146 Chapter 5 ActionScript Core Language Elements See also break continue while...
Page 808: ...808 Chapter 7 ActionScript for Flash...
Page 810: ...810 Appendix A Deprecated Flash 4 operators...
Page 815: ...Other keys 815 Num Lock 144 186 187 _ 189 191 192 219 220 221 222 Key Key code...
Page 816: ...816 Appendix B Keyboard Keys and Key Code Values...
Page 822: ...822 Index...