09_if.zig 712 B

12345678910111213141516171819202122232425262728293031
  1. //
  2. // Now we get into the fun stuff, starting with the 'if' statement!
  3. //
  4. // if (true) {
  5. // // stuff
  6. // } else {
  7. // // other stuff
  8. // }
  9. //
  10. // Zig has the usual comparison operators such as:
  11. //
  12. // a == b a equals b
  13. // a < b a is less than b
  14. // a !=b a does not equal b
  15. //
  16. // The important thing about Zig's 'if' is that it *only* accepts
  17. // boolean values. It won't coerce numbers or other types of data
  18. // to true and false.
  19. //
  20. const std = @import("std");
  21. pub fn main() void {
  22. const foo = 1;
  23. if (foo) {
  24. // We want out program to print this message!
  25. std.debug.print("Foo is 1!\n", .{});
  26. } else {
  27. std.debug.print("Foo is not 1!\n", .{});
  28. }
  29. }