Bird
0
0

Which of the following is the correct syntax to stop a while True loop when a variable count reaches 5?

easy📝 Syntax Q12 of 15
Python - While Loop

Which of the following is the correct syntax to stop a while True loop when a variable count reaches 5?

count = 0
while True:
    count += 1
    ?
Aif count == 5: break
Bif count = 5: break
Cif count == 5: continue
Dif count > 5: stop
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct comparison operator

    Use == to compare values, so if count == 5 is correct.
  2. Step 2: Use break to exit the loop

    The break statement stops the loop immediately when the condition is true.
  3. Final Answer:

    if count == 5: break -> Option A
  4. Quick Check:

    Use == and break to stop loop [OK]
Quick Trick: Use double equals (==) for comparison and break to stop [OK]
Common Mistakes:
MISTAKES
  • Using single equals (=) instead of double equals (==)
  • Using continue instead of break
  • Using undefined commands like stop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes