diff --git a/exercises/045_optionals.zig b/exercises/045_optionals.zig index 494c960..1763f6b 100644 --- a/exercises/045_optionals.zig +++ b/exercises/045_optionals.zig @@ -29,7 +29,7 @@ pub fn main() void { // Please threaten the result so that answer is either the // integer value from deepThought() OR the number 42: - const answer: u8 = result; + const answer: u8 = result orelse 42; std.debug.print("The Ultimate Answer: {}.\n", .{answer}); } diff --git a/exercises/046_optionals2.zig b/exercises/046_optionals2.zig index b5fffbb..74a29b4 100644 --- a/exercises/046_optionals2.zig +++ b/exercises/046_optionals2.zig @@ -22,7 +22,7 @@ const std = @import("std"); const Elephant = struct { letter: u8, - tail: *Elephant = null, // Hmm... tail needs something... + tail: ?*Elephant = null, // Hmm... tail needs something... visited: bool = false, }; @@ -63,9 +63,12 @@ fn visitElephants(first_elephant: *Elephant) void { // We should stop once we encounter a tail that // does NOT point to another element. What can // we put here to make that happen? + if (e.tail == null) { + break; + } // HINT: We want something similar to what `.?` does, // but instead of ending the program, we want to exit the loop... - e = e.tail ??? + e = e.tail.?; } }