summaryrefslogtreecommitdiffstatshomepage
path: root/exercises
diff options
context:
space:
mode:
Diffstat (limited to 'exercises')
-rw-r--r--exercises/016_for2.zig11
-rw-r--r--exercises/038_structs2.zig2
-rw-r--r--exercises/047_methods.zig2
-rw-r--r--exercises/058_quiz7.zig2
-rw-r--r--exercises/063_labels.zig2
-rw-r--r--exercises/075_quiz8.zig2
6 files changed, 11 insertions, 10 deletions
diff --git a/exercises/016_for2.zig b/exercises/016_for2.zig
index 1d4496a..4a8d09c 100644
--- a/exercises/016_for2.zig
+++ b/exercises/016_for2.zig
@@ -1,8 +1,9 @@
//
-// For loops also let you store the "index" of the iteration - a
-// number starting with 0 that counts up with each iteration:
+// For loops also let you use the "index" of the iteration, a number
+// that counts up with each iteration. To access the index of iteration,
+// specify a second condition as well as a second capture value.
//
-// for (items) |item, index| {
+// for (items, 0..) |item, index| {
//
// // Do something with item and index
//
@@ -23,8 +24,8 @@ pub fn main() void {
// Now we'll convert the binary bits to a number value by adding
// the value of the place as a power of two for each bit.
//
- // See if you can figure out the missing piece:
- for (bits) |bit, ???| {
+ // See if you can figure out the missing pieces:
+ for (bits, ???) |bit, ???| {
// Note that we convert the usize i to a u32 with
// @intCast(), a builtin function just like @import().
// We'll learn about these properly in a later exercise.
diff --git a/exercises/038_structs2.zig b/exercises/038_structs2.zig
index 4f2ce48..af7eb1f 100644
--- a/exercises/038_structs2.zig
+++ b/exercises/038_structs2.zig
@@ -44,7 +44,7 @@ pub fn main() void {
// it do and why?
// Printing all RPG characters in a loop:
- for (chars) |c, num| {
+ for (chars, 0..) |c, num| {
std.debug.print("Character {} - G:{} H:{} XP:{}\n", .{
num + 1, c.gold, c.health, c.experience,
});
diff --git a/exercises/047_methods.zig b/exercises/047_methods.zig
index a99c004..96d4c8e 100644
--- a/exercises/047_methods.zig
+++ b/exercises/047_methods.zig
@@ -86,7 +86,7 @@ pub fn main() void {
aliens_alive = 0;
// Loop through every alien by reference (* makes a pointer capture value)
- for (aliens) |*alien| {
+ for (&aliens) |*alien| {
// *** Zap the alien with the heat ray here! ***
???.zap(???);
diff --git a/exercises/058_quiz7.zig b/exercises/058_quiz7.zig
index 0d5bcaa..3069710 100644
--- a/exercises/058_quiz7.zig
+++ b/exercises/058_quiz7.zig
@@ -239,7 +239,7 @@ const HermitsNotebook = struct {
// We'll often want to find an entry by Place. If one is not
// found, we return null.
fn getEntry(self: *HermitsNotebook, place: *const Place) ?*NotebookEntry {
- for (self.entries) |*entry, i| {
+ for (&self.entries, 0..) |*entry, i| {
if (i >= self.end_of_entries) break;
// Here's where the hermit got stuck. We need to return
diff --git a/exercises/063_labels.zig b/exercises/063_labels.zig
index f82ea6d..79adfaa 100644
--- a/exercises/063_labels.zig
+++ b/exercises/063_labels.zig
@@ -106,7 +106,7 @@ pub fn main() void {
const meal = food_loop: for (menu) |food| {
// Now look at each required ingredient for the Food...
- for (food.requires) |required, required_ingredient| {
+ for (food.requires, 0..) |required, required_ingredient| {
// This ingredient isn't required, so skip it.
if (!required) continue;
diff --git a/exercises/075_quiz8.zig b/exercises/075_quiz8.zig
index e05830e..c2dbc1a 100644
--- a/exercises/075_quiz8.zig
+++ b/exercises/075_quiz8.zig
@@ -102,7 +102,7 @@ const HermitsNotebook = struct {
end_of_entries: u8 = 0,
fn getEntry(self: *HermitsNotebook, place: *const Place) ?*NotebookEntry {
- for (self.entries) |*entry, i| {
+ for (&self.entries, 0..) |*entry, i| {
if (i >= self.end_of_entries) break;
if (place == entry.*.?.place) return &entry.*.?;
}