Bird
0
0

Find the error in this code snippet:

medium📝 Debug Q14 of 15
Python - Loop Control
Find the error in this code snippet:
i = 0
while i < 5:
    if i == 3:
        continue
    print(i)
    i += 1
AInfinite loop because i is not incremented when i == 3
BSyntaxError due to missing colon
CPrints numbers 0 to 4 correctly
DTypeError because of continue in while loop
Step-by-Step Solution
Solution:
  1. Step 1: Analyze loop and continue effect

    When i equals 3, continue skips the rest, so i += 1 is not executed.
  2. Step 2: Understand consequence

    Since i stays 3 forever, the loop never ends, causing an infinite loop.
  3. Final Answer:

    Infinite loop because i is not incremented when i == 3 -> Option A
  4. Quick Check:

    continue skips i++ causes infinite loop [OK]
Quick Trick: Increment loop variable before continue or use else [OK]
Common Mistakes:
MISTAKES
  • Ignoring that continue skips increment
  • Thinking continue causes syntax error
  • Assuming loop ends normally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes