···11//
22// If statements are also valid expressions:
33//
44-// var foo: u8 = if (a) 2 else 3;
44+// const foo: u8 = if (a) 2 else 3;
55//
66const std = @import("std");
7788pub fn main() void {
99- var discount = true;
99+ const discount = true;
10101111 // Please use an if...else expression to set "price".
1212 // If discount is true, the price should be $17, otherwise $20:
1313- var price: u8 = if ???;
1313+ const price: u8 = if ???;
14141515 std.debug.print("With the discount, the price is ${}.\n", .{price});
1616}
+1-1
exercises/016_for2.zig
···2929 // Note that we convert the usize i to a u32 with
3030 // @intCast(), a builtin function just like @import().
3131 // We'll learn about these properly in a later exercise.
3232- var place_value = std.math.pow(u32, 2, @intCast(u32, i));
3232+ const place_value = std.math.pow(u32, 2, @intCast(u32, i));
3333 value += place_value * bit;
3434 }
3535
+1-1
exercises/017_quiz2.zig
···13131414function main() void {
1515 var i: u8 = 1;
1616- var stop_at: u8 = 16;
1616+ const stop_at: u8 = 16;
17171818 // What kind of loop is this? A 'for' or a 'while'?
1919 ??? (i <= stop_at) : (i += 1) {
···22// What's really nice is that you can use a switch statement as an
33// expression to return a value.
44//
55-// var a = switch (x) {
55+// const a = switch (x) {
66// 1 => 9,
77// 2 => 16,
88// 3 => 7,
+1-1
exercises/036_enums2.zig
···99// @enumToInt(). We'll learn about builtins properly in a later
1010// exercise.
1111//
1212-// var my_stuff: u8 = @enumToInt(Stuff.foo);
1212+// const my_stuff: u8 = @enumToInt(Stuff.foo);
1313//
1414// Note how that built-in function starts with "@" just like the
1515// @import() function we've been using.
+1-1
exercises/045_optionals.zig
···29293030 // Please threaten the result so that answer is either the
3131 // integer value from deepThought() OR the number 42:
3232- var answer: u8 = result;
3232+ const answer: u8 = result;
33333434 std.debug.print("The Ultimate Answer: {}.\n", .{answer});
3535}
+1-1
exercises/047_methods.zig
···7878 };
79798080 var aliens_alive = aliens.len;
8181- var heat_ray = HeatRay{ .damage = 7 }; // We've been given a heat ray weapon.
8181+ const heat_ray = HeatRay{ .damage = 7 }; // We've been given a heat ray weapon.
82828383 // We'll keep checking to see if we've killed all the aliens yet.
8484 while (aliens_alive > 0) {
···4343 //
4444 // We'll convert this weight from tons to kilograms at a
4545 // conversion of 907.18kg to the ton.
4646- var shuttle_weight: f16 = 907.18 * 2200;
4646+ const shuttle_weight: f16 = 907.18 * 2200;
47474848 // By default, float values are formatted in scientific
4949 // notation. Try experimenting with '{d}' and '{d:.3}' to see
+2-2
patches/patches/010_if2.patch
···1113c13
22-< var price: u8 = if ???;
22+< const price: u8 = if ???;
33---
44-> var price: u8 = if (discount) 17 else 20;
44+> const price: u8 = if (discount) 17 else 20;