summaryrefslogtreecommitdiffstatshomepage
path: root/exercises/016_for2.zig
diff options
context:
space:
mode:
authorChris Boesch <chrboesch@noreply.codeberg.org>2023-02-21 21:43:40 +0100
committerChris Boesch <chrboesch@noreply.codeberg.org>2023-02-21 21:43:40 +0100
commite7326dc5f92dd8a2dc8bd7cafb5b3eaaf55ce99b (patch)
tree62e312ad4ea0cb66d1c9fbd6e259f21ee38dec60 /exercises/016_for2.zig
parentf9b3d5082435dff928647c3e42d0a85ac1159aee (diff)
dev.1711 - switched to multi-object-for-loops
Diffstat (limited to 'exercises/016_for2.zig')
-rw-r--r--exercises/016_for2.zig11
1 files changed, 6 insertions, 5 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.