Enums
You will learn
The two ways to declare an enum and how a switch reads a value.
pub enum Color { Red, Green, Blue } names three cases. The Zig form pub const Mode = enum(u8) { Idle, Run } also fixes the type that stores a case, here u8. A switch over a value lists what each case gives and uses else for the rest. Both forms compile clean on all 7 backends in the lesson spec.
Try it
Add a fourth color to Color and update CASES_IN_COLOR so the test passes.

The two enum forms the t27 compiler accepts, side by side with their cases. Lesson 18 of the t27 basics course.
specs/basics/18_enums.t27
// SPDX-License-Identifier: Apache-2.0
; t27 basics, lesson 18: Enums.
; An enum names a fixed set of cases, and switch picks one of them.
module basics_18_enums;
pub enum Color {
Red,
Green,
Blue,
}
pub const Mode = enum(u8) {
Idle,
Run,
};
pub const CASES_IN_COLOR : u8 = 3;
test color_has_three_cases {
assert CASES_IN_COLOR == 3;
}
All lessons
Module 1 · A spec file
What a .t27 file holds: a module line, prose lines and comments.
Module 2 · Values and types
Constants, the width of a whole number, and true, false and text.
Module 3 · Arrays, trits and expressions
Lists of values, the three values of a trit, and what operators compute.
Module 4 · Tests and functions
A test block, several small tests in one spec, and a function with typed inputs.
Module 5 · Inside a function
Names with let and var, choices with if and switch, and loops.
Module 6 · Visibility and your own types
What pub shares with other modules, and the structs and enums you declare.
Module 7 · Modules, rules and gen-ts
Reading another module, stating a rule that always holds, and a spec turned into TypeScript.
Module 8 · The compiler and tri
The backends t27c writes, the stages it reads a spec in, and the tri command.
Module 9 · Errors, a program, what next
Reading a compiler error, one small complete program, and the course to take next.