From bef099fee6f5a24036d1f02fcc43fe4b849c5528 Mon Sep 17 00:00:00 2001 From: Dave Gauer Date: Sun, 30 Apr 2023 17:11:37 -0400 Subject: Renamed 095 to "for3" to match feature sequence So 100 will be the next in line. --- build.zig | 2 +- exercises/095_for3.zig | 73 +++++++++++++++++++++++++++++++++++++ exercises/095_for_loops.zig | 73 ------------------------------------- patches/patches/095_for3.patch | 4 ++ patches/patches/095_for_loops.patch | 4 -- 5 files changed, 78 insertions(+), 78 deletions(-) create mode 100644 exercises/095_for3.zig delete mode 100644 exercises/095_for_loops.zig create mode 100644 patches/patches/095_for3.patch delete mode 100644 patches/patches/095_for_loops.patch diff --git a/build.zig b/build.zig index 398f02e..4cd5ef7 100644 --- a/build.zig +++ b/build.zig @@ -500,7 +500,7 @@ const exercises = [_]Exercise{ .C = true, }, .{ - .main_file = "095_for_loops.zig", + .main_file = "095_for3.zig", .output = "1 2 4 7 8 11 13 14 16 17 19", }, .{ diff --git a/exercises/095_for3.zig b/exercises/095_for3.zig new file mode 100644 index 0000000..e4c4662 --- /dev/null +++ b/exercises/095_for3.zig @@ -0,0 +1,73 @@ +// +// The Zig language is in rapid development and continuously +// improves the language constructs. Ziglings evolves with it. +// +// Until version 0.11, Zig's 'for' loops did not directly +// replicate the functionality of the C-style: "for(a;b;c)" +// which are so well suited for iterating over a numeric +// sequence. +// +// Instead, 'while' loops with counters clumsily stood in their +// place: +// +// var i: usize = 0; +// while (i < 10) : (i += 1) { +// // Here variable 'i' will have each value 0 to 9. +// } +// +// But here we are in the glorious future and Zig's 'for' loops +// can now take this form: +// +// for (0..10) |i| { +// // Here variable 'i' will have each value 0 to 9. +// } +// +// The key to understanding this example is to know that '0..9' +// uses the new range syntax: +// +// 0..10 is a range from 0 to 9 +// 1..4 is a range from 1 to 3 +// +// At the moment, ranges are only supported in 'for' loops. +// +// Perhaps you recall Exercise 13? We were printing a numeric +// sequence like so: +// +// var n: u32 = 1; +// +// // I want to print every number between 1 and 20 that is NOT +// // divisible by 3 or 5. +// while (n <= 20) : (n += 1) { +// // The '%' symbol is the "modulo" operator and it +// // returns the remainder after division. +// if (n % 3 == 0) continue; +// if (n % 5 == 0) continue; +// std.debug.print("{} ", .{n}); +// } +// +// Let's try out the new form of 'for' to re-implement that +// exercise: +// +const std = @import("std"); + +pub fn main() void { + + // I want to print every number between 1 and 20 that is NOT + // divisible by 3 or 5. + for (???) |n| { + + // The '%' symbol is the "modulo" operator and it + // returns the remainder after division. + if (n % 3 == 0) continue; + if (n % 5 == 0) continue; + std.debug.print("{} ", .{n}); + } + + std.debug.print("\n", .{}); +} +// +// That's a bit nicer, right? +// +// Of course, both 'while' and 'for' have different advantages. +// Exercises 11, 12, and 14 would NOT be simplified by switching +// a 'while' for a 'for'. diff --git a/exercises/095_for_loops.zig b/exercises/095_for_loops.zig deleted file mode 100644 index e4c4662..0000000 --- a/exercises/095_for_loops.zig +++ /dev/null @@ -1,73 +0,0 @@ -// -// The Zig language is in rapid development and continuously -// improves the language constructs. Ziglings evolves with it. -// -// Until version 0.11, Zig's 'for' loops did not directly -// replicate the functionality of the C-style: "for(a;b;c)" -// which are so well suited for iterating over a numeric -// sequence. -// -// Instead, 'while' loops with counters clumsily stood in their -// place: -// -// var i: usize = 0; -// while (i < 10) : (i += 1) { -// // Here variable 'i' will have each value 0 to 9. -// } -// -// But here we are in the glorious future and Zig's 'for' loops -// can now take this form: -// -// for (0..10) |i| { -// // Here variable 'i' will have each value 0 to 9. -// } -// -// The key to understanding this example is to know that '0..9' -// uses the new range syntax: -// -// 0..10 is a range from 0 to 9 -// 1..4 is a range from 1 to 3 -// -// At the moment, ranges are only supported in 'for' loops. -// -// Perhaps you recall Exercise 13? We were printing a numeric -// sequence like so: -// -// var n: u32 = 1; -// -// // I want to print every number between 1 and 20 that is NOT -// // divisible by 3 or 5. -// while (n <= 20) : (n += 1) { -// // The '%' symbol is the "modulo" operator and it -// // returns the remainder after division. -// if (n % 3 == 0) continue; -// if (n % 5 == 0) continue; -// std.debug.print("{} ", .{n}); -// } -// -// Let's try out the new form of 'for' to re-implement that -// exercise: -// -const std = @import("std"); - -pub fn main() void { - - // I want to print every number between 1 and 20 that is NOT - // divisible by 3 or 5. - for (???) |n| { - - // The '%' symbol is the "modulo" operator and it - // returns the remainder after division. - if (n % 3 == 0) continue; - if (n % 5 == 0) continue; - std.debug.print("{} ", .{n}); - } - - std.debug.print("\n", .{}); -} -// -// That's a bit nicer, right? -// -// Of course, both 'while' and 'for' have different advantages. -// Exercises 11, 12, and 14 would NOT be simplified by switching -// a 'while' for a 'for'. diff --git a/patches/patches/095_for3.patch b/patches/patches/095_for3.patch new file mode 100644 index 0000000..c258b7b --- /dev/null +++ b/patches/patches/095_for3.patch @@ -0,0 +1,4 @@ +57c57 +< for (???) |n| { +--- +> for (1..21) |n| { diff --git a/patches/patches/095_for_loops.patch b/patches/patches/095_for_loops.patch deleted file mode 100644 index c258b7b..0000000 --- a/patches/patches/095_for_loops.patch +++ /dev/null @@ -1,4 +0,0 @@ -57c57 -< for (???) |n| { ---- -> for (1..21) |n| { -- cgit v1.2.3