Skip to content

Language: add when statement modelled after Odin and Nim#473

Open
chqrlie wants to merge 1 commit intoc2lang:masterfrom
chqrlie:when-stmt
Open

Language: add when statement modelled after Odin and Nim#473
chqrlie wants to merge 1 commit intoc2lang:masterfrom
chqrlie:when-stmt

Conversation

@chqrlie
Copy link
Copy Markdown
Contributor

@chqrlie chqrlie commented Mar 22, 2026

  • when has the same syntax as if but with these restrictions:
    • condition must be a compile time constant value
    • if true, only the then branch is analysed and generated
    • otherwise, only the else branch, if present, is analysed and generated
    • when blocks do not start a new scope
    • when cannot appear as the sole statement in if, else, for or while

@chqrlie chqrlie force-pushed the when-stmt branch 4 times, most recently from 88801b5 to 1148196 Compare March 28, 2026 08:17
* `when` has the same syntax as `if` but with these restrictions:
  * condition must be a compile time constant value
  * if true, only the *then* branch is analysed and generated
  * otherwise, only the *else* branch, if present, is analysed and generated
  * `when` blocks do not start a new scope
  * `when` cannot appear as the sole statement in `if`, `else`, `for` or `while`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant