Bird
0
0

When does the else block NOT run in a while loop?

easy📝 Conceptual Q2 of 15
Python - While Loop
When does the else block NOT run in a while loop?
AWhen the loop condition is false initially
BWhen the loop runs at least once
CWhen the loop has no break statement
DWhen the loop contains a break statement that executes
Step-by-Step Solution
Solution:
  1. Step 1: Identify when else skips

    The else block is skipped only if the loop exits due to a break statement.
  2. Step 2: Check other cases

    If the loop condition is false initially, else still runs because loop ends normally without break.
  3. Final Answer:

    When the loop contains a break statement that executes -> Option D
  4. Quick Check:

    Else skips only on break exit [OK]
Quick Trick: Else skips only if break runs inside while [OK]
Common Mistakes:
MISTAKES
  • Assuming else skips if loop never runs
  • Thinking else runs only if loop runs once
  • Confusing loop condition with break

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes