From de353bcb3b6d7ef59bcf1ceb0a326ab6e5a4139f Mon Sep 17 00:00:00 2001 From: mikkurogue Date: Sat, 4 Jan 2025 11:56:25 +0000 Subject: [PATCH] Update: 108 Labeled switch example to contain default case for exhaustion Update example text to give clarity on default/exhaustive case. Reasoning: The input for the example will not compile if user would want to test this for the logic of a labeled switch. Due the input not being an exhaustive input but rather "any u8 integer" (for the lack of better terminology) we need to use the else branch to indicate that the default case is handled, in this case by just emulating the '4' branch, but this could return an error.InvalidCaseProvided for example. Signed-off-by: mikkurogue --- exercises/108_labeled_switch.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/exercises/108_labeled_switch.zig b/exercises/108_labeled_switch.zig index 88cb196..d506cac 100644 --- a/exercises/108_labeled_switch.zig +++ b/exercises/108_labeled_switch.zig @@ -35,6 +35,7 @@ // 2 => continue :foo 3, // 3 => return, // 4 => {}, +// else => {}, // } // std.debug.print("This statement cannot be reached"); // } @@ -46,6 +47,9 @@ // 3. In the case '2' we repeat the same pattern as case '1' // but instead the value to be evaluated is now '3'; // 4. Finally we get to case '3', where we return from the function as a whole. +// 5. In this example as the input has no clear exhaustive patterns but a essentially +// any u8 integer, we need do need to handle any case that is not explicitly handled +// by using the `else => {}` branch as a default case. // // Since step 4 or a break stament do not exist in this switch, the debug statement is // never executed