this
break statement
break exits the current loop (or switch).
continue exits the current repetition of the loop
(going back to the test, and, possibly, to another repetition of
the loop).
label: statement and then use
break label to break out of that statement.
For example
outer:
for (i = 0; i < N; ++i) {
inner:
for (j= 0; j < M; ++j) {
if (meetsCondition(i,j)) {
System.out.println(
"Found what we were looking for at (" +
i + "," + j + ")"
);
break outer;
} // if
} // inner for loop
// Here's where you go if you break out of the inner loop
} // outer for loop
// Here's where you go if you break out of the outer loop
continue can take a label, and returns to the
next iteration of the labeled loop.
As a take-home exercise, you are requested to do the following:
for loop.
finally clause to that loop.
break out of that loop.
finally
clause to the inner loop of a pair of nested loops, and
break out of the outer loop while in the inner loop.
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
Source text last modified Tue Oct 7 17:12:32 1997.
This page generated on Wed Nov 5 12:38:42 1997 by SiteWeaver.
Contact our webmaster at rebelsky@math.grin.edu