Bird
Raised Fist0

What will be the output of this code simulating a performance test?

medium📝 Predict Output Q5 of Q15
Testing Fundamentals - Non-Functional Testing
What will be the output of this code simulating a performance test?
max_users = 10
current_users = 0
while current_users < max_users:
    current_users += 2
print(f"Users reached: {current_users}")
AUsers reached: 10
BUsers reached: 12
CUsers reached: 8
DUsers reached: 0
Step-by-Step Solution
Solution:
  1. Step 1: Trace the loop increments

    current_users starts at 0; while current_users < 10: increment by 2 -> 2, 4, 6, 8, 10. After increment to 10, condition check 10 < 10 is false, loop exits. But since increment happens inside loop, last increment makes current_users 12.
  2. Step 2: Understand loop exit condition

    Loop runs while current_users < max_users; increments by 2 each time. When current_users is 8, next increment makes it 10 (still < 10?), then next increment makes it 12, which breaks the loop.
  3. Final Answer:

    Users reached: 12 -> Option B
  4. Quick Check:

    Loop increments can overshoot condition [OK]
Quick Trick: While loop increments can overshoot exit condition [OK]
Common Mistakes:
MISTAKES
  • Thinking loop exits exactly at max_users
  • Not tracing last increment
  • Confusing less than with less or equal

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Testing Fundamentals Quizzes