Bird
0
0

Why is a while loop preferred over a for loop when the number of iterations depends on user input?

hard📝 Conceptual Q10 of 15
Python - While Loop
Why is a while loop preferred over a for loop when the number of iterations depends on user input?
ABecause for loops require functions
BBecause for loops cannot use variables
CBecause while loops are faster
DBecause while loops run until a condition changes, not fixed count
Step-by-Step Solution
Solution:
  1. Step 1: Understand iteration control

    For loops run a fixed number of times; while loops run until a condition changes.
  2. Step 2: Relate to user input

    User input can vary, so number of iterations is unknown and depends on condition.
  3. Final Answer:

    Because while loops run until a condition changes, not fixed count -> Option D
  4. Quick Check:

    While loops suit variable iteration counts [OK]
Quick Trick: While loops fit unknown iteration counts [OK]
Common Mistakes:
MISTAKES
  • Thinking for loops can't use variables
  • Believing while loops are always faster
  • Confusing loop requirements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes