10_if2.zig 501 B

1234567891011121314151617181920
  1. //
  2. // If statements are also valid expressions:
  3. //
  4. // foo = if (a) 2 else 3;
  5. //
  6. // Note: you'll need to declare a variable type when assigning a value
  7. // from a statement like this because the compiler isn't smart enough
  8. // to infer the type for you.
  9. //
  10. const std = @import("std");
  11. pub fn main() void {
  12. var discount = true;
  13. // If discount is true, the price should be $17, otherwise $20:
  14. var price = if ???;
  15. std.debug.print("With the discount, the price is ${}.\n", .{price});
  16. }