Bird
0
0

Why do we use a while loop in Python instead of a for loop?

easy📝 Conceptual Q11 of 15
Python - While Loop
Why do we use a while loop in Python instead of a for loop?
ABecause <code>for</code> loops cannot repeat code.
BBecause we don't always know how many times the loop should run before starting.
CBecause <code>while</code> loops are faster than <code>for</code> loops.
DBecause <code>while</code> loops do not need a condition.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the difference between while and for loops

    for loops run a fixed number of times, while while loops run as long as a condition is true.
  2. Step 2: Identify when while loops are needed

    while loops are useful when the number of repetitions is unknown before starting.
  3. Final Answer:

    Because we don't always know how many times the loop should run before starting. -> Option B
  4. Quick Check:

    Unknown repetitions = use while loop [OK]
Quick Trick: Use while when repeat count is unknown before start [OK]
Common Mistakes:
MISTAKES
  • Thinking for loops can handle unknown repetitions
  • Believing while loops don't need conditions
  • Confusing speed differences between loops

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes