23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

else if (second_boolean_exp)<br />

else<br />

second_true_statement<br />

false_statement<br />

If the first Boolean expression is false, the second Boolean expression will be<br />

tested, <strong>and</strong> so on. An if statement can have an arbitrary number of else if<br />

parts.<br />

For example, the follow<strong>in</strong>g is a correct if statement.<br />

if (snowLevel < 2) {<br />

}<br />

goToClass();<br />

comeHome();<br />

else if (snowLevel < 5) {<br />

}<br />

else<br />

goSledd<strong>in</strong>g();<br />

haveSnowballFight();<br />

stayAtHome();<br />

Switch Statements<br />

<strong>Java</strong> provides for multiple-value control flow us<strong>in</strong>g the switch statement, which is<br />

especially useful with enum types. The follow<strong>in</strong>g is an <strong>in</strong>dicative example (based<br />

on a variable d of the Day enum type of Section 1.1.3).<br />

switch (d) {<br />

case MON:<br />

52

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

Saved successfully!

Ooh no, something went wrong!