02.02.2013 Views

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9: Using loops<br />

Now instead of testing for the case where the loop variable i reaches a certain value, we look<br />

for when the sum gets <strong>to</strong> a certain value. The ‘for’ loop is best used with a loop variable that<br />

is incremented by a regular amount, usually one, and the test is for the loop variable reaching<br />

a certain value. The ‘while’ loop is best used when the knowledge of the loop condition is<br />

not so closely allied <strong>to</strong> the loop variable. It is possible with both constructions <strong>to</strong> create a loop<br />

that never terminates. In such circumstances your computer will briefly hang until <strong>Flash</strong> realizes<br />

that something un<strong>to</strong>ward is going on and offers a dialog box enabling you <strong>to</strong> terminate the<br />

use of scripts in the existing program. Here are two obvious examples of loops that will never<br />

terminate:<br />

//Example A<br />

sum = 0;<br />

for (i=0; i1000) then the code block is exited<br />

using the break statement.<br />

121

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!