Java Reference
In-Depth Information
obj.inside(this); // let it know it's inside me
}
}
To terminate an outer loop or block, you label the outer statement and
use its label name in the break statement:
private float[][] matrix;
public boolean workOnFlag(float flag) {
int y, x;
boolean found = false;
search:
for (y = 0; y < matrix.length; y++) {
for (x = 0; x < matrix[y].length; x++) {
if (matrix[y][x] == flag) {
found = true;
break search;
}
}
}
if (!found)
return false;
// do some stuff with flagged value at matrix[y][x]
return true;
}
Here we label the outer for loop and if we find the value we are looking
for, we terminate both inner and outer loops by using a labeled break .
This simplifies the logic of the loops because we do not need to add a
!found clause in the loop expressions.
 
Search WWH ::




Custom Search