046_optionals2.patch 587 B

12345678910111213141516171819
  1. --- exercises/046_optionals2.zig 2024-09-04 20:51:36.766783971 +0200
  2. +++ answers/046_optionals2.zig 2024-09-04 20:51:01.389400985 +0200
  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. }