30.06.2013 Views

X - AS Nida

X - AS Nida

X - AS Nida

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.

The switch Statement<br />

The switch Statement<br />

The switch Statement<br />

The switch Statement<br />

A switch statement can have an optional default<br />

case<br />

The expression of a switch statement must result in<br />

either int or char type<br />

The default case has no associated value and simply<br />

uses the reserved word default<br />

Often a break statement is used as the last statement<br />

in each case's statement list<br />

If the default case is present, control will transfer to it<br />

if no other case value matches<br />

A break statement causes control to transfer to the<br />

end of the switch statement<br />

Though the default case can be positioned anywhere<br />

in the switch, usually it is placed at the end<br />

If a break statement is not used, the flow of control<br />

will continue into the next case<br />

If there is no default case, and no other value<br />

matches, control falls through to the statement after<br />

the switch<br />

18<br />

17<br />

Logical NOT<br />

Logical NOT<br />

Logical Operators<br />

Logical Operators<br />

The logical NOT !<br />

Boolean expressions can use the following logical<br />

operators:<br />

if (!(x < 0))<br />

System.out.println (x);<br />

! Logical NOT<br />

&& Logical AND<br />

|| Logical OR<br />

They all take boolean operands and produce boolean<br />

results<br />

If x is not less than 0, x is printed.<br />

20<br />

19

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

Saved successfully!

Ooh no, something went wrong!