Bird
0
0

Analyze the following code and identify the issue:

medium📝 Debug Q7 of 15
Python - Loop Control
Analyze the following code and identify the issue:
count = 0
while count < 4:
    if count == 2:
        continue
    print(count)
    count += 1
AThe code will print numbers 0 to 3 correctly
BThe loop will run infinitely because count is not incremented when count == 2
CSyntax error due to missing colon
DThe continue statement is misplaced and causes a runtime error
Step-by-Step Solution
Solution:
  1. Step 1: Trace the loop

    When count == 2, continue skips the increment step.
  2. Step 2: Effect of skipping increment

    Since count is not incremented, it remains 2, causing an infinite loop.
  3. Final Answer:

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

    Does count increase on continue? No. Infinite loop? Yes. [OK]
Quick Trick: Increment must not be skipped before continue [OK]
Common Mistakes:
MISTAKES
  • Ignoring that continue skips increment
  • Assuming loop ends automatically
  • Confusing continue with break

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes