Endless 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
  

INDEX, Introduction to Loops, While Loops, Endless Loops, for Loops, do while Loops, Spinning Stars, Stop stars created dynamically
Next lesson: Arrays

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Endless Loops