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(5):
    if i == 2:
        break
    print(i)
A0 1
B0 1 2
C2
D0 1 2 3 4
Step-by-Step Solution
Solution:
  1. Step 1: Trace loop iterations and break condition

    The loop runs i from 0 to 4. When i equals 2, break stops the loop immediately.
  2. Step 2: Identify printed values before break

    Values 0 and 1 are printed before i reaches 2 and breaks.
  3. Final Answer:

    0 1 -> Option A
  4. Quick Check:

    Break stops loop at i=2, prints before break [OK]
Quick Trick: Break stops loop before printing current value if condition met [OK]
Common Mistakes:
MISTAKES
  • Including the break value in output
  • Printing after break executes
  • Confusing break with continue

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes