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:
for i in range(4):
    if i == 2:
        continue
    print(i)
    break
AThe break is inside the loop and will stop after first iteration
Bcontinue is used incorrectly and causes syntax error
CThe loop will never run because of break before print
DNo error, code runs and prints 0, 1, 3
Step-by-Step Solution
Solution:
  1. Step 1: Understand loop flow with continue and break

    When i == 2, continue skips print and break for that iteration. For other values, print runs then break stops loop immediately.
  2. Step 2: Identify effect of break placement

    Break inside the loop after print causes loop to stop after first printed value, so only one value prints.
  3. Final Answer:

    The break is inside the loop and will stop after first iteration -> Option A
  4. Quick Check:

    Break stops loop early due to placement [OK]
Quick Trick: Break after print stops loop early, continue skips iteration [OK]
Common Mistakes:
MISTAKES
  • Thinking continue causes syntax error
  • Assuming loop prints all values
  • Ignoring break effect inside loop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes