Loops

Occasionally, a programmer writes a loop that never ends. In fact, it is really easy to write an endless loop. If you create an endless loop, the user will get a message that something is making the script run really slow, and asks if they would like to end the movie. You do not want the user to see that message, so you should check for endless loops very carefully. The code below is an endless loop because the values for num that are generated are 0, 2, 4, 6, … and it is NEVER 5!  If you want to try this save the file first, then wait for Flash to crash!

var num:int=0;
while(num!=5) {
   trace(num);
   num=num+2;
} //loop

NEXT: for Loops