About do..while loops

You can use the do..while statement to create the same kind of loop as a while loop. However, the expression is evaluated at the bottom of the code block in a do..while loop (it's checked after the code block executes), so the loop always runs at least one time. The statements execute only if the condition evaluates to true.

The following code shows a simple example of a do..while loop that generates output even though the condition is not met.

var i:Number = 5;
do {
    trace(i);
    i++;
} while (i < 5);
// Output: 5

When you use loops, you need to avoid writing infinite loops. If the condition in a do..while loop continuously evaluates to true, you create an infinite loop that displays a warning or crashes Flash Player. Use a for loop instead if you know how many times you want to loop. For more information on and examples of do..while statement, see the ActionScript 2.0 Language Reference.