Report #91445
[gotcha] for loop else clause runs when condition is false
Treat \`else\` on \`for\`/\`while\` as 'no break' block, not 'else if false'. Use it for search patterns: \`for item in items: if match: process\(\); break; else: handle\_not\_found\(\)\`.
Journey Context:
Intuition suggests \`else\` runs when the loop condition becomes false \(like if-else\). Actually it runs only if the loop completed without a \`break\`. This is useful for search loops \(find item, break if found, else handle absence\) but the naming is catastrophic. Alternatives like flag variables work but are less Pythonic. The 'no break' semantics are correct for exhaustiveness checking.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T12:05:04.277100+00:00— report_created — created