Warum ist es eine schlechte Praxis, break / continue-Bezeichnungen in OOP zu verwenden (z. B. Java, C #)? [geschlossen]
Mir wurde gesagt, dass die Verwendung von break and continue-Bezeichnungen in einer OOP-Sprache kein OOP-Programmierstil ist. Können Sie im Detail erklären, warum und wo das Problem liegt?
Der Trick war mit diesem Labelwort. Ich meinte mit break / continue.
class BreakWithLabelDemo {
public static void main(String[] args) {
int[][] arrayOfInts = {
{ 32, 87, 3, 589 },
{ 12, 1076, 2000, 8 },
{ 622, 127, 77, 955 }
};
int searchfor = 12;
int i;
int j = 0;
boolean foundIt = false;
search:
for (i = 0; i < arrayOfInts.length; i++) {
for (j = 0; j < arrayOfInts[i].length;
j++) {
if (arrayOfInts[i][j] == searchfor) {
foundIt = true;
break search;
}
}
}
if (foundIt) {
System.out.println("Found " + searchfor +
" at " + i + ", " + j);
} else {
System.out.println(searchfor +
" not in the array");
}
}
}
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html