diff options
author | Dave Gauer <ratfactor@gmail.com> | 2022-01-06 18:08:43 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-06 18:08:43 -0500 |
commit | 0efa4c124265ca5c009d63942d863e3911ea3197 (patch) | |
tree | 62a24ae4a7c56aa5251cf5f2f35d8e706e1cd961 | |
parent | d61a6e847425cf6fc8bb84bc1ffa59d259d85ccc (diff) | |
parent | 669d4f7337d43628fd031888d9dc46d22289fcdf (diff) | |
download | ziglings-0efa4c124265ca5c009d63942d863e3911ea3197.tar.gz ziglings-0efa4c124265ca5c009d63942d863e3911ea3197.tar.bz2 ziglings-0efa4c124265ca5c009d63942d863e3911ea3197.tar.xz ziglings-0efa4c124265ca5c009d63942d863e3911ea3197.zip |
Merge pull request #88 from adamu/const
use const for variables that are never modified
-rw-r--r-- | exercises/021_errors.zig | 2 | ||||
-rw-r--r-- | exercises/031_switch2.zig | 2 | ||||
-rw-r--r-- | exercises/033_iferror.zig | 4 | ||||
-rw-r--r-- | exercises/063_labels.zig | 4 |
4 files changed, 6 insertions, 6 deletions
diff --git a/exercises/021_errors.zig b/exercises/021_errors.zig index cbb5ac8..7afeace 100644 --- a/exercises/021_errors.zig +++ b/exercises/021_errors.zig @@ -16,7 +16,7 @@ const MyNumberError = error{ const std = @import("std"); pub fn main() void { - var nums = [_]u8{ 2, 3, 4, 5, 6 }; + const nums = [_]u8{ 2, 3, 4, 5, 6 }; for (nums) |n| { std.debug.print("{}", .{n}); diff --git a/exercises/031_switch2.zig b/exercises/031_switch2.zig index 1b3acdb..d8af6e6 100644 --- a/exercises/031_switch2.zig +++ b/exercises/031_switch2.zig @@ -15,7 +15,7 @@ pub fn main() void { const lang_chars = [_]u8{ 26, 9, 7, 42 }; for (lang_chars) |c| { - var real_char: u8 = switch (c) { + const real_char: u8 = switch (c) { 1 => 'A', 2 => 'B', 3 => 'C', diff --git a/exercises/033_iferror.zig b/exercises/033_iferror.zig index f281b8d..6ba0c61 100644 --- a/exercises/033_iferror.zig +++ b/exercises/033_iferror.zig @@ -29,12 +29,12 @@ const MyNumberError = error{ const std = @import("std"); pub fn main() void { - var nums = [_]u8{ 2, 3, 4, 5, 6 }; + const nums = [_]u8{ 2, 3, 4, 5, 6 }; for (nums) |num| { std.debug.print("{}", .{num}); - var n = numberMaybeFail(num); + const n = numberMaybeFail(num); if (n) |value| { std.debug.print("={}. ", .{value}); } else |err| switch (err) { diff --git a/exercises/063_labels.zig b/exercises/063_labels.zig index cdde229..f82ea6d 100644 --- a/exercises/063_labels.zig +++ b/exercises/063_labels.zig @@ -103,7 +103,7 @@ pub fn main() void { const wanted_ingredients = [_]u8{ 0, 3 }; // Chili, Cheese // Look at each Food on the menu... - var meal = food_loop: for (menu) |food| { + const meal = food_loop: for (menu) |food| { // Now look at each required ingredient for the Food... for (food.requires) |required, required_ingredient| { @@ -115,7 +115,7 @@ pub fn main() void { // (Remember that want_it will be the index number of // the ingredient based on its position in the // required ingredient list for each food.) - var found = for (wanted_ingredients) |want_it| { + const found = for (wanted_ingredients) |want_it| { if (required_ingredient == want_it) break true; } else false; |