|
@@ -15,11 +15,11 @@
|
|
// 1 => { op = 2; continue; },
|
|
// 1 => { op = 2; continue; },
|
|
// 2 => { op = 3; continue; },
|
|
// 2 => { op = 3; continue; },
|
|
// 3 => return,
|
|
// 3 => return,
|
|
-// 4 => {},
|
|
|
|
|
|
+// else => {},
|
|
// }
|
|
// }
|
|
// break;
|
|
// break;
|
|
// }
|
|
// }
|
|
-// std.debug.print("This statement cannot be reached");
|
|
|
|
|
|
+// std.debug.print("This statement cannot be reached\n", .{});
|
|
// }
|
|
// }
|
|
//
|
|
//
|
|
// By combining all we've learned so far, we can now proceed with a labeled switch
|
|
// By combining all we've learned so far, we can now proceed with a labeled switch
|
|
@@ -36,23 +36,21 @@
|
|
// 3 => return,
|
|
// 3 => return,
|
|
// else => {},
|
|
// else => {},
|
|
// }
|
|
// }
|
|
-// std.debug.print("This statement cannot be reached");
|
|
|
|
|
|
+// std.debug.print("This statement cannot be reached\n", .{});
|
|
// }
|
|
// }
|
|
//
|
|
//
|
|
// The flow of execution on this second case is:
|
|
// The flow of execution on this second case is:
|
|
// 1. The switch starts with value '1';
|
|
// 1. The switch starts with value '1';
|
|
// 2. The switch evaluates to case '1' which in turn uses the continue statement
|
|
// 2. The switch evaluates to case '1' which in turn uses the continue statement
|
|
-// to re-evaluate the labeled switch again, now providing the value '2';
|
|
|
|
|
|
+// to re-evaluate the labeled switch again, now providing the value '2';
|
|
// 3. In the case '2' we repeat the same pattern as case '1'
|
|
// 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.
|
|
|
|
|
|
+// 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,
|
|
|
|
+// so the debug statement is never executed.
|
|
// 5. In this example, since the input does not have clear, exhaustive patterns and
|
|
// 5. In this example, since the input does not have clear, exhaustive patterns and
|
|
-// can essentially be any `u8` integer, we need to handle all cases not explicitly
|
|
|
|
-// covered by using the `else => {}` branch as the default case.
|
|
|
|
-
|
|
|
|
|
|
+// can essentially be any 'u8' integer, we need to handle all cases not explicitly
|
|
|
|
+// covered by using the 'else => {}' branch as the default case.
|
|
//
|
|
//
|
|
-// Since step 4 or a break stament do not exist in this switch, the debug statement is
|
|
|
|
-// never executed
|
|
|
|
//
|
|
//
|
|
const std = @import("std");
|
|
const std = @import("std");
|
|
|
|
|