aboutsummaryrefslogtreecommitdiff
path: root/09_if.zig
diff options
context:
space:
mode:
authorDave Gauer <dave@ratfactor.com>2021-01-08 17:53:22 -0500
committerDave Gauer <dave@ratfactor.com>2021-01-08 17:53:22 -0500
commit0bb89e3e41cef893c158326a209aec129382c275 (patch)
tree9b306d886616628485dcecb1c822911853313bb2 /09_if.zig
parentb9b89737fca7cc80b7d1b1527445e0ec71b25dda (diff)
downloadziglings-0bb89e3e41cef893c158326a209aec129382c275.tar.gz
ziglings-0bb89e3e41cef893c158326a209aec129382c275.tar.bz2
ziglings-0bb89e3e41cef893c158326a209aec129382c275.tar.xz
ziglings-0bb89e3e41cef893c158326a209aec129382c275.zip
Added Ex 9,10 for If
Diffstat (limited to '09_if.zig')
-rw-r--r--09_if.zig31
1 files changed, 31 insertions, 0 deletions
diff --git a/09_if.zig b/09_if.zig
new file mode 100644
index 0000000..3309cbf
--- /dev/null
+++ b/09_if.zig
@@ -0,0 +1,31 @@
+//
+// Now we get into the fun stuff, starting with the 'if' statement!
+//
+// if (true) {
+// // stuff
+// } else {
+// // other stuff
+// }
+//
+// Zig has the usual comparison operators such as:
+//
+// a == b a equals b
+// a < b a is less than b
+// a !=b a does not equal b
+//
+// The important thing about Zig's 'if' is that it *only* accepts
+// boolean values. It won't coerce numbers or other types of data
+// to true and false.
+//
+const std = @import("std");
+
+pub fn main() void {
+ const foo = 1;
+
+ if (foo) {
+ // We want out program to print this message!
+ std.debug.print("Foo is 1!\n", .{});
+ } else {
+ std.debug.print("Foo is not 1!\n", .{});
+ }
+}