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.

switch to exit the statement once the appropriate choice is found. However, the break<br />

statement‘s use is also commonly associated with loops, which are discussed next.<br />

Note <strong>The</strong> switch statement wasn’t introduced into the language until <strong>JavaScript</strong> 1.2 so it<br />

should be used carefully in very archaic browsers of concern.<br />

Loops<br />

It is often necessary to iterate a number of statements until a particular condition is true. For<br />

example, you might wish to perform the same operation on each element of an array until you<br />

hit the end of the array. Like many other languages, <strong>JavaScript</strong> enables this behavior with<br />

looping statements. Loops continue to execute the body of their code until a halting condition is<br />

reached. <strong>JavaScript</strong> supports while, do/while, for, and for/in loops. An example of a while<br />

loop is<br />

var x=0;<br />

while (x

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

Saved successfully!

Ooh no, something went wrong!