Bird
0
0

Identify the error in this code snippet using continue:

medium📝 Debug Q14 of 15
C - Loop Control Statements
Identify the error in this code snippet using continue:
int i = 0;
while (i < 5) {
    if (i == 2)
        continue;
    printf("%d ", i);
    i++;
}
ASyntax error: continue cannot be used in while loops
BThe printf statement is unreachable
CThe loop will run infinitely because 'i' is not incremented when i == 2
DThe variable 'i' is not declared properly
Step-by-Step Solution
Solution:
  1. Step 1: Understand loop flow with continue

    When i equals 2, continue skips the rest of the loop body, so i++ is not executed.
  2. Step 2: Consequence of skipping i++

    Since i is not incremented at i == 2, the loop condition remains true forever, causing an infinite loop.
  3. Final Answer:

    The loop will run infinitely because 'i' is not incremented when i == 2 -> Option C
  4. Quick Check:

    continue skips i++ causing infinite loop [OK]
Quick Trick: Always increment loop variable before continue to avoid infinite loops [OK]
Common Mistakes:
  • Thinking continue causes syntax error
  • Assuming printf is unreachable
  • Ignoring loop variable increment

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes