Difficulty: Easy
Correct Answer: Compilation fails.
Explanation:
Introduction / Context:
This question tests knowledge of labeled statements and the valid contexts for continue in Java. Although labels can prefix many statements, continue has strict usage rules.
Given Data / Assumptions:
Concept / Approach:
In Java, continue (with or without a label) can only target a loop statement. A labeled continue must reference the label of an enclosing loop. Placing a label on a non-loop statement (such as an if) does not create a valid target for continue. The compiler enforces this rule, producing an error such as "continue outside of loop" or "undefined label for continue."
Step-by-Step Solution:
Verification / Alternative check:
Replace the if with a for(;;) loop and keep the label; the code compiles and the labeled continue will jump to the loop’s next iteration.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming any labeled statement can be the target of continue; only loops qualify (for, while, do-while).
Final Answer:
Compilation fails.
Discussion & Comments