Bird
0
0

Find the error in this code that tries to skip printing number 2:

medium📝 Debug Q14 of 15
Python - Loop Control
Find the error in this code that tries to skip printing number 2:
for i in range(4):
    if i = 2:
        continue
    print(i)
AMissing colon after if statement
BUsing '=' instead of '==' in if condition
Ccontinue cannot be used in loops
Drange(4) is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check if condition syntax

    The code uses '=' which is assignment, not comparison; it should be '=='.
  2. Step 2: Validate other syntax parts

    Colon is present, continue is valid in loops, and range(4) is correct.
  3. Final Answer:

    Using '=' instead of '==' in if condition -> Option B
  4. Quick Check:

    Comparison needs '==' not '=' [OK]
Quick Trick: Use '==' for comparison, '=' is assignment [OK]
Common Mistakes:
MISTAKES
  • Using '=' instead of '==' in conditions
  • Thinking continue is invalid in loops
  • Ignoring syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes