14.07.2013 Views

Contents - Cultural View

Contents - Cultural View

Contents - Cultural View

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.

Java syntax 183<br />

outer:<br />

for (int i = 0; i < 10; i++) {<br />

}<br />

while (true) {<br />

}<br />

break outer;<br />

// Will break to this point<br />

continue statement<br />

The continue statement discontinues the current iteration of the current control statement and begins the next<br />

iteration. The following while loop in the code above reads characters by calling getChar(), skipping the statements<br />

in the body of the loop if the characters are spaces:<br />

int ch;<br />

while (ch = getChar()) {<br />

}<br />

if (ch == ' ')<br />

continue; // Skips the rest of the while-loop<br />

// Rest of the while-loop, will not be reached if ch == ' '<br />

doSomething();<br />

Labels can be specified in continue statements, as they can in break statements:<br />

outer:<br />

for (String str : stringsArr) {<br />

}<br />

char[] strChars = str.toCharArray();<br />

for (char ch : strChars) {<br />

}<br />

if (ch == ' ') {<br />

}<br />

return statement<br />

/* Continues the outer cycle and the next<br />

string is retrieved from stringsArr */<br />

continue outer;<br />

doSomething(ch);<br />

The return statement is used to end method execution and to return a value. A value returned by the method is<br />

written after the return keyword. If the method returns anything but void, it must use the return statement to return<br />

some value.<br />

void doSomething(boolean streamClosed) {<br />

}<br />

// If streamClosed is true, execution is stopped<br />

if (streamClosed) {<br />

}<br />

return;<br />

readFromStream();

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

Saved successfully!

Ooh no, something went wrong!