2021-01-08 23:53:22 +01:00
|
|
|
//
|
|
|
|
// Now we get into the fun stuff, starting with the 'if' statement!
|
|
|
|
//
|
2021-02-07 17:06:51 +01:00
|
|
|
// if (true) {
|
|
|
|
// ...
|
|
|
|
// } else {
|
|
|
|
// ...
|
|
|
|
// }
|
2021-01-08 23:53:22 +01:00
|
|
|
//
|
2021-02-07 17:06:51 +01:00
|
|
|
// Zig has the "usual" comparison operators such as:
|
2021-01-08 23:53:22 +01:00
|
|
|
//
|
2021-02-07 17:06:51 +01:00
|
|
|
// a == b means "a equals b"
|
|
|
|
// a < b means "a is less than b"
|
2021-08-17 09:01:55 +02:00
|
|
|
// a > b means "a is greater than b"
|
2021-02-15 22:55:19 +01:00
|
|
|
// a != b means "a does not equal b"
|
2021-01-08 23:53:22 +01:00
|
|
|
//
|
2021-02-07 17:06:51 +01:00
|
|
|
// The important thing about Zig's "if" is that it *only* accepts
|
2021-01-08 23:53:22 +01:00
|
|
|
// 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;
|
|
|
|
|
2021-02-07 17:06:51 +01:00
|
|
|
// Please fix this condition:
|
2021-01-08 23:53:22 +01:00
|
|
|
if (foo) {
|
2021-02-14 15:22:41 +01:00
|
|
|
// We want our program to print this message!
|
2021-01-08 23:53:22 +01:00
|
|
|
std.debug.print("Foo is 1!\n", .{});
|
|
|
|
} else {
|
|
|
|
std.debug.print("Foo is not 1!\n", .{});
|
|
|
|
}
|
|
|
|
}
|