Summary
Allow break <expr> so loop expressions can return a value.
Motivation
Supports expression-oriented style while preserving explicit early-exit behavior.
Proposed Semantics
- Loop expression type is nullable/optional
T?
break value yields T
- Exhausting loop without value break yields
null
Example
let first_even = for n in nums {
if n % 2 == 0 { break n; }
}
// first_even: Int?
Scope
- Parser support for
break with optional value
- Type checker support for loop result typing (
T?) and break value consistency
- Runtime support for carrying break values out of loop execution
Out of Scope
for...else
- Non-loop break targets
Acceptance Criteria
- Loop with
break n type-checks as T?
- Loop without value break evaluates to
null
- Type error when break values in same loop are inconsistent
Summary
Allow
break <expr>so loop expressions can return a value.Motivation
Supports expression-oriented style while preserving explicit early-exit behavior.
Proposed Semantics
T?break valueyieldsTnullExample
Scope
breakwith optional valueT?) and break value consistencyOut of Scope
for...elseAcceptance Criteria
break ntype-checks asT?null