11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

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.

}<br />

document.write(count+"");<br />

count++;<br />

document.write("Loop done!");<br />

In this situation, the value of count is initially zero, and then the loop enters, the value of count<br />

is output, and the value is increased. <strong>The</strong> body of the loop repeats until count reaches 10, at<br />

which point the conditional expression becomes false. At this point, the loop exits and executes<br />

the statement following the loop body. <strong>The</strong> output of the loop is shown here:<br />

<strong>The</strong> initialization, loop, and conditional expression can be set up in a variety of ways. Consider<br />

this loop that counts downward from 100 in steps of 10 or more:<br />

var count = 100;<br />

while (count >> 10)<br />

{<br />

}<br />

document.write(count+"");<br />

if (count == 50)<br />

else<br />

count = count – 20;<br />

count = count - 10;<br />

One issue with while loops is that, depending on the loop test expression, the loop may never<br />

actually execute.<br />

var count = 0;<br />

while (count >> 0)

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

Saved successfully!

Ooh no, something went wrong!