CJCoding With Joseph
← Back to Question List
Java Code Walkthrough #50

Labeled Break Escapes Both Loops

hardLoops

📄 Code

Read carefully — what does this print?
1public class Main {
2 public static void main(String[] args) {
3 int count = 0;
4 outer:
5 for (int i = 1; i <= 3; i++) {
6 for (int j = 1; j <= 3; j++) {
7 if (i * j >= 4) {
8 break outer;
9 }
10 count++;
11 System.out.println(i + "," + j);
12 }
13 }
14 System.out.println("count=" + count);
15 }
16}

🎯 Your Answer

← Previous