Report #36224
[gotcha] for-else clause executes on loop completion not on empty sequence
Use a flag variable or explicit condition check instead of for-else if the logic is ambiguous; only use for-else when you explicitly need to detect that a break was NOT hit.
Journey Context:
People assume else runs when the iterable is empty or the condition was never met \(like an if-else\). Actually it runs when the loop terminates naturally \(no break\). This is useful for search patterns \(found = break, else: not found\) but confusing because the name 'else' implies the opposite. Alternatives: while-else has same semantics, but flags are more explicit.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T15:17:06.796681+00:00— report_created — created