Design decisions

125. Loops take an else that runs when no break left them (2026-11-21)

  • Decision. for and while accept a trailing else: block at the loop's indentation, with Python's meaning: it runs when the loop ends without break (labelled break 'outer from an inner loop also skips the inner loop's else). Labelled break / continue stay as settled in 4.6.
  • Why. "Search, and handle not-found" is a common contest shape that otherwise needs a found flag, which is a stale-state bug site.
  • Reverse. Delete the form; a codemod rewrites it to a flag.
  • Status. Implemented (parser, checker, formatter, LSP, IR, interpreter, and C++17 codegen; parity test crates/cpl-cli/tests/programs/loop_else.cp, fmt test formats_loop_else, LSP test folding_ranges_cover_loop_else).