0
0
Javaprogramming~10 mins

Labeled break and continue in Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to break out of the outer loop using a label.

Java
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);
    }
}
Drag options to blanks, or click blank then click option'
Abreak
Bstop
Cexit
Dcontinue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'continue' instead of 'break' to exit the loop.
Forgetting to specify the label after break.
2fill in blank
medium

Complete the code to skip the current iteration of the outer loop using a labeled continue.

Java
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);
    }
}
Drag options to blanks, or click blank then click option'
Askip
Bbreak
Cexit
Dcontinue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'break' instead of 'continue' to skip iteration.
Not specifying the label after continue.
3fill in blank
hard

Fix the error in the labeled break statement to correctly exit the outer loop.

Java
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);
    }
}
Drag options to blanks, or click blank then click option'
Abreak; outer
Bbreak outer
Cbreakouter
Dbreak.outer
Attempts:
3 left
💡 Hint
Common Mistakes
Writing 'breakouter' as one word.
Adding a semicolon between break and label.
4fill in blank
hard

Fill both blanks to use labeled continue and break correctly in nested loops.

Java
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);
    }
}
Drag options to blanks, or click blank then click option'
Acontinue
Bbreak
Cexit
Dskip
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up break and continue keywords.
Using labels incorrectly or forgetting them.
5fill in blank
hard

Fill all three blanks to create a labeled break and continue example that skips and breaks loops properly.

Java
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);
    }
}
Drag options to blanks, or click blank then click option'
Abreak
Bcontinue
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing break and continue keywords.
Using the wrong label with the keyword.