aboutsummaryrefslogtreecommitdiff
path: root/27_defer.zig
diff options
context:
space:
mode:
authorDave Gauer <dave@ratfactor.com>2021-01-31 17:48:34 -0500
committerDave Gauer <dave@ratfactor.com>2021-01-31 17:48:34 -0500
commitc70fa5f58f5ca2dc010f00caee19027069a09131 (patch)
tree9f7d352065d282c15a75aa4c4168216e69a762f8 /27_defer.zig
parent2de8a8c54d7090dd063bed8b6b283c2fcb452e43 (diff)
downloadziglings-c70fa5f58f5ca2dc010f00caee19027069a09131.tar.gz
ziglings-c70fa5f58f5ca2dc010f00caee19027069a09131.tar.bz2
ziglings-c70fa5f58f5ca2dc010f00caee19027069a09131.tar.xz
ziglings-c70fa5f58f5ca2dc010f00caee19027069a09131.zip
Adding exs 27-32
Diffstat (limited to '27_defer.zig')
-rw-r--r--27_defer.zig25
1 files changed, 25 insertions, 0 deletions
diff --git a/27_defer.zig b/27_defer.zig
new file mode 100644
index 0000000..b41e2af
--- /dev/null
+++ b/27_defer.zig
@@ -0,0 +1,25 @@
+//
+// You can assign some code to run _after_ a block of code exits by
+// deferring it with a "defer" statement:
+//
+// {
+// defer runLater();
+// runNow();
+// }
+//
+// In the example above, runLater() will run when the block ({...})
+// is finished. So the code above will run in the following order:
+//
+// runNow();
+// runLater();
+//
+// This feature seems strange at first, but we'll see how it could be
+// useful in the next exercise.
+const std = @import("std");
+
+pub fn main() void {
+ // Without changing anything else, please add a 'defer' statement
+ // to this code so that our program prints "One Two\n":
+ std.debug.print("Two\n", .{});
+ std.debug.print("One ", .{});
+}