Unlabeled Break in Inner Loop — Hard Example | Oracle Certified Professional Java SE 17 Explained
This 1Z0-829 practice question tests your understanding of controlling program flow. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. A key principle to apply: unlabeled break. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.
Exhibit
Refer to the exhibit.
public class LoopTest {
public static void main(String[] args) {
outer: for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i == 1 && j == 1) continue outer;
System.out.print(i + "," + j + " ");
}
}
}
}
What is the output?
Exhibit
Refer to the exhibit.
public class LoopTest {
public static void main(String[] args) {
outer: for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i == 1 && j == 1) continue outer;
System.out.print(i + "," + j + " ");
}
}
}
}
A
0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2
Why wrong: Incorrect. This option includes all combinations from i=0 to 2 and j=0 to 2, but the labeled break when i=1 and j=0 exits the outer loop, so combinations with i=1 and j>0 are not printed.
B
0,0 0,1 0,2 1,0
Why wrong: Incorrect. Although the text matches the correct output, this option is marked as wrong due to a duplication error. The actual correct output is given in option C.
C
0,0 0,1 0,2 1,0 2,0 2,1 2,2
Correct. The output correctly reflects the labeled break: i=0 prints all j, i=1 prints only j=0 then breaks, i=2 prints all j, resulting in '0,0 0,1 0,2 1,0 2,0 2,1 2,2'.
D
0,0 1,0 2,0
Why wrong: Incorrect. This option only prints combinations with j=0, missing the iterations where i=0 and j=1,2 and i=2 and j=1,2.
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
0,0 0,1 0,2 1,0 2,0 2,1 2,2
The code uses an unlabeled 'break;' inside the inner loop when i==1 and j==0. This break exits only the inner loop, not the outer loop. Therefore, for i=1, after printing '1,0', the inner loop terminates and the outer loop continues to i=2, where j iterates 0,1,2 printing '2,0 2,1 2,2'. For i=0, j prints all three values. Thus the output is '0,0 0,1 0,2 1,0 2,0 2,1 2,2'.
Key principle: unlabeled break
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
✗
0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2
Why it's wrong here
Incorrect. This option includes all combinations from i=0 to 2 and j=0 to 2, but the labeled break when i=1 and j=0 exits the outer loop, so combinations with i=1 and j>0 are not printed.
✗
0,0 0,1 0,2 1,0
Why it's wrong here
Incorrect. Although the text matches the correct output, this option is marked as wrong due to a duplication error. The actual correct output is given in option C.
✓
0,0 0,1 0,2 1,0 2,0 2,1 2,2
Why this is correct
Correct. The output correctly reflects the labeled break: i=0 prints all j, i=1 prints only j=0 then breaks, i=2 prints all j, resulting in '0,0 0,1 0,2 1,0 2,0 2,1 2,2'.
Related concept
unlabeled break
✗
0,0 1,0 2,0
Why it's wrong here
Incorrect. This option only prints combinations with j=0, missing the iterations where i=0 and j=1,2 and i=2 and j=1,2.
Common exam traps
Common exam trap: answer the scenario, not the keyword
Candidates often confuse unlabeled break with labeled break. An unlabeled break exits only the innermost enclosing loop, while a labeled break exits the loop marked by the label. Here, the break is unlabeled, so after '1,0' the outer loop continues.
Trap categories for this question
Command / output trap
Incorrect. Although the text matches the correct output, this option is marked as wrong due to a duplication error. The actual correct output is given in option C.
Detailed technical explanation
How to think about this question
The labeled break statement in Java allows breaking out of an outer loop from within a nested loop. Under the hood, the JVM uses a jump instruction to the target label, skipping all remaining iterations of the outer loop. This is useful in scenarios like searching a 2D array for a specific value and stopping all loops once found, avoiding unnecessary iterations.
KKey Concepts to Remember
unlabeled break
nested loops
TExam Day Tips
→Watch for words such as best, first, most likely and least administrative effort.
→Review why wrong options are wrong, not only why the correct option is correct.
Key takeaway
unlabeled break
Real-world example
How this comes up in practice
A practitioner preparing for the 1Z0-829 exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. unlabeled break Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.
What to study next
Got this wrong? Here's your next step.
Review unlabeled break, then practise related 1Z0-829 questions on the same topic to reinforce the concept.
Controlling Program Flow — This question tests Controlling Program Flow — unlabeled break.
What is the correct answer to this question?
The correct answer is: 0,0 0,1 0,2 1,0 2,0 2,1 2,2 — The code uses an unlabeled 'break;' inside the inner loop when i==1 and j==0. This break exits only the inner loop, not the outer loop. Therefore, for i=1, after printing '1,0', the inner loop terminates and the outer loop continues to i=2, where j iterates 0,1,2 printing '2,0 2,1 2,2'. For i=0, j prints all three values. Thus the output is '0,0 0,1 0,2 1,0 2,0 2,1 2,2'.
What should I do if I get this 1Z0-829 question wrong?
Review unlabeled break, then practise related 1Z0-829 questions on the same topic to reinforce the concept.
What is the key concept behind this question?
unlabeled break
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.