23.04.2013 Views

javascript

javascript

javascript

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.

} else if (! looseLeafTea[i]) {<br />

looseLeafTea.splice(i, 1);<br />

continue;<br />

} else {<br />

i ++;<br />

}<br />

}<br />

return "glum";<br />

}<br />

"I feel " + findTea("Kenilworth") + "!";<br />

// "I feel cheery!"<br />

As Figure 4–10 illustrates, invoking our function findTea() evaluates to "cheery" or "glum"<br />

depending upon whether JavaScript can find the value of the tea parameter in looseLeafTea.<br />

Figure 4–10. Inside a function, you can abort a while loop with a return statement.<br />

■ Note Chapter 6 covers functions more fully.<br />

CHAPTER 4 ■ CONTROLLING FLOW<br />

121

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

Saved successfully!

Ooh no, something went wrong!