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
        break
    print(i)
    i += 1
AMissing colon after if condition
BBreak cannot be used in while loops
CVariable i is not incremented
DPrint statement is outside the loop
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of if statement

    The if statement must end with a colon (:). Here it is missing.
  2. Step 2: Verify other parts

    Break is allowed in while loops, i is incremented, and print is inside the loop.
  3. Final Answer:

    Missing colon after if condition -> Option A
  4. Quick Check:

    Syntax error due to missing colon = D [OK]
Quick Trick: If statements always need a colon at the end [OK]
Common Mistakes:
MISTAKES
  • Forgetting colon after if
  • Thinking break is invalid in while
  • Ignoring indentation errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes