Bird
0
0

What is the output of the following code?

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

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

    Values 0, 1, and 2 are printed. When i reaches 3, loop stops before printing 3.
  3. Final Answer:

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

    break stops loop at 3, prints before it [OK]
Quick Trick: Break stops loop before printing current value [OK]
Common Mistakes:
MISTAKES
  • Including the break value in output
  • Confusing break with continue
  • Assuming loop runs fully

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes