mirror of
https://git.aramjonghu.dev/AramJonghu/ziglings.git
synced 2026-09-05 17:53:30 +02:00
optionals done
This commit is contained in:
@@ -29,7 +29,7 @@ pub fn main() void {
|
|||||||
|
|
||||||
// Please threaten the result so that answer is either the
|
// Please threaten the result so that answer is either the
|
||||||
// integer value from deepThought() OR the number 42:
|
// 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});
|
std.debug.print("The Ultimate Answer: {}.\n", .{answer});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const std = @import("std");
|
|||||||
|
|
||||||
const Elephant = struct {
|
const Elephant = struct {
|
||||||
letter: u8,
|
letter: u8,
|
||||||
tail: *Elephant = null, // Hmm... tail needs something...
|
tail: ?*Elephant = null, // Hmm... tail needs something...
|
||||||
visited: bool = false,
|
visited: bool = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -63,9 +63,12 @@ fn visitElephants(first_elephant: *Elephant) void {
|
|||||||
// We should stop once we encounter a tail that
|
// We should stop once we encounter a tail that
|
||||||
// does NOT point to another element. What can
|
// does NOT point to another element. What can
|
||||||
// we put here to make that happen?
|
// we put here to make that happen?
|
||||||
|
if (e.tail == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// HINT: We want something similar to what `.?` does,
|
// HINT: We want something similar to what `.?` does,
|
||||||
// but instead of ending the program, we want to exit the loop...
|
// but instead of ending the program, we want to exit the loop...
|
||||||
e = e.tail ???
|
e = e.tail.?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user