Complete the code to break out of the outer loop using a label.
outer: for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (i == 1 && j == 1) { [1] outer; } System.out.println(i + "," + j); } }
The break statement with a label exits the labeled loop immediately.
Complete the code to skip the current iteration of the outer loop using a labeled continue.
outer: for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (j == 1) { [1] outer; } System.out.println(i + "," + j); } }
The continue statement with a label skips the current iteration of the labeled loop.
Fix the error in the labeled break statement to correctly exit the outer loop.
outer: for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { if (i == 1 && j == 0) { [1] outer; } System.out.println(i + "," + j); } }
The correct syntax for labeled break is break labelName; without spaces inside the keyword.
Fill both blanks to use labeled continue and break correctly in nested loops.
outer: for (int i = 0; i < 3; i++) { inner: for (int j = 0; j < 3; j++) { if (j == 1) { [1] outer; } if (i == 2) { [2] inner; } System.out.println(i + "," + j); } }
continue outer; skips to the next iteration of the outer loop.
break inner; exits the inner loop.
Fill all three blanks to create a labeled break and continue example that skips and breaks loops properly.
outer: for (int i = 0; i < 4; i++) { inner: for (int j = 0; j < 4; j++) { if (i == 1 && j == 2) { [1] inner; } if (i == 3 && j == 1) { [2] outer; } if (j == 0) { [3] inner; } System.out.println(i + "," + j); } }
Use break inner; to exit inner loop, continue outer; to skip outer loop iteration, and continue inner; to skip inner loop iteration.