Java Reference
In-Depth Information
A labeled continue will break out of any inner loops on its way to the
next iteration of the named loop. No label is required on the continue
in the preceding example since there is only one enclosing loop. Con-
sider, however, nested loops that iterate over the values of a two-di-
mensional matrix. Suppose that the matrix is symmetric ( matrix[i][j]==
matrix[j][i] ). In that case, you need only iterate through half of the
matrix. For example, here is a method that doubles each value in a sym-
metric matrix:
static void doubleUp(int[][] matrix) {
int order = matrix.length;
column:
for (int i = 0; i < order; i++) {
for (int j = 0; j < order; j++) {
matrix[i][j] = matrix[j][i] = matrix[i][j]*2;
if (i == j)
continue column;
}
}
}
Each time a diagonal element of the matrix is reached, the rest of that
row is skipped by continuing with the outer loop that iterates over the
columns.
 
Search WWH ::




Custom Search