This commit is contained in:
Adam Millerchip 2021-12-26 13:58:08 +09:00
parent 32bc21cebc
commit 0bd5b2aa0d
1 changed files with 3 additions and 2 deletions

View File

@ -29,17 +29,18 @@ const MyNumberError = error{
const std = @import("std");
pub fn main() void {
var nums = [_]u8{ 2, 3, 4, 5, 6 };
const nums = [_]u8{ 2, 3, 4, 5, 6 };
for (nums) |num| {
std.debug.print("{}", .{num});
var n = numberMaybeFail(num);
const n = numberMaybeFail(num);
if (n) |value| {
std.debug.print("={}. ", .{value});
} else |err| switch (err) {
MyNumberError.TooBig => std.debug.print(">4. ", .{}),
// Please add a match for TooSmall here and have it print: "<4. "
MyNumberError.TooSmall => std.debug.print("<4. ", .{}),
}
}