Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q4 of 15
Python - Loop Control
What will be the output of this code?
for i in range(4):
    if i == 2:
        break
    print(i)
A0 1
B0 1 2 3
C0 1 2
D2 3
Step-by-Step Solution
Solution:
  1. Step 1: Trace loop iterations

    Loop runs i from 0 to 3. When i is 2, break stops loop.
  2. Step 2: Identify printed values

    Print happens before break, so prints 0 and 1 only.
  3. Final Answer:

    0 1 -> Option A
  4. Quick Check:

    break stops loop early = 0 1 [OK]
Quick Trick: break stops loop immediately [OK]
Common Mistakes:
MISTAKES
  • Including 2 in output
  • Printing after break
  • Confusing break with continue

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes