046_optionals2.patch 587 B

12345678910111213141516171819
  1. --- exercises/046_optionals2.zig 2024-11-08 22:46:25.592875338 +0100
  2. +++ answers/046_optionals2.zig 2024-11-08 22:46:20.699447951 +0100
  3. @@ -22,7 +22,7 @@
  4. const Elephant = struct {
  5. letter: u8,
  6. - tail: *Elephant = null, // Hmm... tail needs something...
  7. + tail: ?*Elephant = null, // Hmm... tail needs something...
  8. visited: bool = false,
  9. };
  10. @@ -66,6 +66,6 @@
  11. // HINT: We want something similar to what `.?` does,
  12. // but instead of ending the program, we want to exit the loop...
  13. - e = e.tail ???
  14. + e = e.tail orelse break;
  15. }
  16. }