Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q13 of 15
Python - Loop Control
What will be the output of this code?
for i in range(5):
    if i == 3:
        break
    print(i)
A3 4
B0 1 2 3 4
C0 1 2
D0 1 2 3
Step-by-Step Solution
Solution:
  1. Step 1: Analyze loop iterations and break condition

    The loop runs from 0 to 4, but breaks when i == 3.
  2. Step 2: Determine printed values before break

    Values 0, 1, 2 are printed; loop stops before printing 3.
  3. Final Answer:

    0 1 2 -> Option C
  4. Quick Check:

    Loop breaks at 3, prints before break = 0 1 2 [OK]
Quick Trick: Break stops loop before printing the break value [OK]
Common Mistakes:
MISTAKES
  • Including 3 in output
  • Printing all numbers ignoring break
  • Confusing break with continue

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes