Skip to content

Add break as value for loop expressions #38

@synapticvoid

Description

@synapticvoid

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions