Difficulty: Easy
Correct Answer: Error: Misplaced continue
Explanation:
Introduction / Context:
This question checks knowledge of valid control statements inside a switch. While break
and goto
are common within a switch, continue
is only meaningful within loops (for, while, do-while).
Given Data / Assumptions:
continue
appears directly in a switch within main, not inside any loop.
Concept / Approach:continue
transfers control to the next loop iteration. Without an enclosing loop, the statement has no valid target and is ill-formed. Most compilers emit an error such as “continue statement not within a loop” or “misplaced continue”.
Step-by-Step Solution:
Parse the switch: cases 1, 2, and 3 exist; default also exists.Encounter continue;
in case 3 without an enclosing loop.Compilation fails with an error about continue’s placement.
Verification / Alternative check:
Wrap the switch inside a loop to make continue
valid: e.g., while(1){ switch(i){ ... case 3: continue; }}
Now continue
would jump to the next loop iteration.
Why Other Options Are Wrong:
No runtime output occurs because compilation fails. Therefore options suggesting printed lines or a hang are incorrect.
Common Pitfalls:
Confusing break
(valid in switch) with continue
(loop-only); thinking continue
behaves like break
in a switch.
Final Answer:
Error: Misplaced continue
Discussion & Comments