I'm with van Rossum there. In 10 years of java programming, I have used a break or continue to a label maybe twice in total.
If that example was my code, you would probably find the outer loop in a "boolean contains(int x, int[][] xs)" method and instead of a "break", you would find a "return true" in the inner loop, removing the need for the "found = true" assignment in the inner loop as well.
Gains: Less variables and labels to track in your mind, a reusable query-method and a more readable main-method:
<pre>
int[][] array = new int[][]{{1,2,3,4},{10,20,30,40}};
if(contains(30, array)){
System.out.println("30 found...")
} else{
System.out.println("30 not found...")
}
</pre>
↧