For the new Zig feature ‘labeled switch’ we received an exercise from a new contributor. Great work!
Try out:
// By combining while loops and switch statements with continue and break statements
// one can create very concise State Machines.
//
// One such example would be:
//
// pub fn main() void {
// var op: u8 = 1;
// while (true) {
// switch (op) {
// 1 => { op = 2; continue; },
// 2 => { op = 3; continue; },
// 3 => return,
// 4 => {},
// }
// break;
// }
// std.debug.print("This statement cannot be reached");
// }
//
// By combining all we've learned so far, we can now proceed with a labeled switch
Ziglings - Learn the Zig programming language by fixing tiny broken programs.