How do exit two nested loops?
Yes, you can write break with label e.g.:
int points = 0;
int goal = 100;
someLabel:
while (goal <= 100) {
for (int i = 0; i < goal; i++) {
if (points > 50) {
break someLabel;
}
points += i;
}
}
// you are going here after break someLabel;
In Java you can use a label to specify which loop to break/continue:
mainLoop:
while (goal <= 100) {
for (int i = 0; i < goal; i++) {
if (points > 50) {
break mainLoop;
}
points += i;
}
}