Skip to content

37 Plain enums ​

An enum lists a finite set of named alternatives.

norm
enum State {
  Ready,
  Running,
  Done
}

main() {
  State current = State.Ready
  printLine(current == State.Ready)
  current = State.Done
  printLine(current == State.Done)
}

Expected output:

text
true
true

State.Ready and State.Done are distinct variants of the same type. The variable can change which variant it holds, while the declaration keeps the possible states closed.

Try it: Add a Paused variant and assign it in main.

Precise rules: Reference.

Norm 0.25