Bird
0
0

What will be printed by this code?

medium📝 Predict Output Q5 of 15
Python - While Loop

What will be printed by this code?

i = 1
while True:
    if i > 4:
        break
    print(i)
    i += 2
A1 3
B1 2 3 4
C2 4 6
D1 3 5
Step-by-Step Solution
Solution:
  1. Step 1: Follow loop iterations

    i starts at 1, prints 1, then increments by 2 to 3, prints 3, then increments to 5.
  2. Step 2: Check break condition

    When i becomes 5, i > 4 is true, loop breaks before printing 5.
  3. Final Answer:

    1 3 -> Option A
  4. Quick Check:

    Prints odd numbers less than 5 = 1 3 [OK]
Quick Trick: Break before print stops output [OK]
Common Mistakes:
MISTAKES
  • Printing after break
  • Incrementing before print
  • Misreading break condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes