15.04.2018 Views

programming-for-dummies

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

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

492<br />

Looping Statements<br />

case value3:<br />

case value4;<br />

Command;<br />

break;<br />

default:<br />

Command;<br />

}<br />

This SWITCH statement is equivalent to the following IF-ELSE statement:<br />

if (expression = value1) || (expression = value2) {<br />

Command;<br />

}<br />

else if (expression = value3) || (expression = value4) {<br />

Command;<br />

}<br />

else {<br />

Command;<br />

}<br />

Looping Statements<br />

A looping statement repeats one or more commands <strong>for</strong> a fixed number of<br />

times or until a certain Boolean condition becomes True. To create a loop<br />

that repeats <strong>for</strong> a fixed number of times, use the FOR loop, which looks like<br />

this:<br />

<strong>for</strong> (startvalue; endvalue; increment) {<br />

Command;<br />

}<br />

If you wanted the FOR loop to run four times, you could set the Start value to<br />

1 and the End value to 4, such as<br />

<strong>for</strong> (i = 1; i

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

Saved successfully!

Ooh no, something went wrong!