Report #10663
[gotcha] for-else loop executes on completion not failure
Treat \`else\` as 'no break' clause; use a flag variable if you need 'item not found' logic, or restructure to avoid for-else entirely for clarity.
Journey Context:
The \`else\` clause runs when the iterable is exhausted normally, not when the condition is false. People intuit 'else' as 'if we didn't find anything', but it actually means 'if we didn't break'. This is useful for search patterns \(break when found, else handle missing\), but the naming makes it a persistent trap that leads to inverted logic bugs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T11:18:08.631085+00:00— report_created — created