mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2024-11-09 19:40:48 -05:00
use const for variables that are never modified
This commit is contained in:
parent
f0357ea91c
commit
39e432748e
4 changed files with 6 additions and 6 deletions
|
@ -16,7 +16,7 @@ const MyNumberError = error{
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
pub fn main() void {
|
pub fn main() void {
|
||||||
var nums = [_]u8{ 2, 3, 4, 5, 6 };
|
const nums = [_]u8{ 2, 3, 4, 5, 6 };
|
||||||
|
|
||||||
for (nums) |n| {
|
for (nums) |n| {
|
||||||
std.debug.print("{}", .{n});
|
std.debug.print("{}", .{n});
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub fn main() void {
|
||||||
const lang_chars = [_]u8{ 26, 9, 7, 42 };
|
const lang_chars = [_]u8{ 26, 9, 7, 42 };
|
||||||
|
|
||||||
for (lang_chars) |c| {
|
for (lang_chars) |c| {
|
||||||
var real_char: u8 = switch (c) {
|
const real_char: u8 = switch (c) {
|
||||||
1 => 'A',
|
1 => 'A',
|
||||||
2 => 'B',
|
2 => 'B',
|
||||||
3 => 'C',
|
3 => 'C',
|
||||||
|
|
|
@ -29,12 +29,12 @@ const MyNumberError = error{
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
pub fn main() void {
|
pub fn main() void {
|
||||||
var nums = [_]u8{ 2, 3, 4, 5, 6 };
|
const nums = [_]u8{ 2, 3, 4, 5, 6 };
|
||||||
|
|
||||||
for (nums) |num| {
|
for (nums) |num| {
|
||||||
std.debug.print("{}", .{num});
|
std.debug.print("{}", .{num});
|
||||||
|
|
||||||
var n = numberMaybeFail(num);
|
const n = numberMaybeFail(num);
|
||||||
if (n) |value| {
|
if (n) |value| {
|
||||||
std.debug.print("={}. ", .{value});
|
std.debug.print("={}. ", .{value});
|
||||||
} else |err| switch (err) {
|
} else |err| switch (err) {
|
||||||
|
|
|
@ -103,7 +103,7 @@ pub fn main() void {
|
||||||
const wanted_ingredients = [_]u8{ 0, 3 }; // Chili, Cheese
|
const wanted_ingredients = [_]u8{ 0, 3 }; // Chili, Cheese
|
||||||
|
|
||||||
// Look at each Food on the menu...
|
// 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...
|
// Now look at each required ingredient for the Food...
|
||||||
for (food.requires) |required, required_ingredient| {
|
for (food.requires) |required, required_ingredient| {
|
||||||
|
@ -115,7 +115,7 @@ pub fn main() void {
|
||||||
// (Remember that want_it will be the index number of
|
// (Remember that want_it will be the index number of
|
||||||
// the ingredient based on its position in the
|
// the ingredient based on its position in the
|
||||||
// required ingredient list for each food.)
|
// 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;
|
if (required_ingredient == want_it) break true;
|
||||||
} else false;
|
} else false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue