027_defer.zig 715 B

1234567891011121314151617181920212223242526
  1. //
  2. // You can assign some code to run _after_ a block of code exits by
  3. // deferring it with a "defer" statement:
  4. //
  5. // {
  6. // defer runLater();
  7. // runNow();
  8. // }
  9. //
  10. // In the example above, runLater() will run when the block ({...})
  11. // is finished. So the code above will run in the following order:
  12. //
  13. // runNow();
  14. // runLater();
  15. //
  16. // This feature seems strange at first, but we'll see how it could be
  17. // useful in the next exercise.
  18. const std = @import("std");
  19. pub fn main() void{
  20. // Without changing anything else, please add a 'defer' statement
  21. // to this code so that our program prints "One Two\n":
  22. defer std.debug.print("Two\n", .{});
  23. std.debug.print("One ", .{});
  24. }