Bird
0
0

In a for-else loop, when will the else block NOT execute?

easy📝 Conceptual Q2 of 15
Python - For Loop
In a for-else loop, when will the else block NOT execute?
AWhen the loop completes all iterations
BWhen the loop contains a <code>break</code> statement that is executed
CWhen the loop has no iterations
DWhen the loop variable is empty
Step-by-Step Solution
Solution:
  1. Step 1: Identify the role of break in for-else

    The else block is skipped if the loop is exited early by a break.
  2. Step 2: Understand loop completion

    If the loop runs fully without break, the else block executes. If break runs, else does not.
  3. Final Answer:

    When the loop contains a break statement that is executed -> Option B
  4. Quick Check:

    else skips if break runs [OK]
Quick Trick: Else skips only if break runs inside loop [OK]
Common Mistakes:
MISTAKES
  • Thinking else skips if loop has no iterations
  • Assuming else runs regardless of break
  • Confusing loop variable emptiness with else execution

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes