diff options
author | Dave Gauer <dave@ratfactor.com> | 2021-02-07 11:06:51 -0500 |
---|---|---|
committer | Dave Gauer <dave@ratfactor.com> | 2021-02-07 11:06:51 -0500 |
commit | adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a (patch) | |
tree | a25511c3bb20069f1d6123366573c82c5745338b /16_for2.zig | |
parent | 507355ec3b1066c707e19816b86ac1fb56fc0385 (diff) | |
download | ziglings-adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a.tar.gz ziglings-adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a.tar.bz2 ziglings-adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a.tar.xz ziglings-adf5ddb27df7f5a22b0b7d3321dfc8bca1e7937a.zip |
Consistent instructions and examples
I started off with "hints" that required the poor student to piece
together the information from incomplete bits. A complete example is
like a picture that is worth 1000 words and far clearer.
Diffstat (limited to '16_for2.zig')
-rw-r--r-- | 16_for2.zig | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/16_for2.zig b/16_for2.zig index 4b01b86..0a62a1a 100644 --- a/16_for2.zig +++ b/16_for2.zig @@ -3,9 +3,15 @@ // number starting with 0 that counts up with each iteration: // // for (items) |item, index| { +// // // Do something with item and index +// // } // +// You can name "item" and "index" anything you want. "i" is a popular +// shortening of "index". The item name is often the singular form of +// the items you're looping through. +// const std = @import("std"); pub fn main() void { @@ -15,9 +21,9 @@ pub fn main() void { var value: u32 = 0; // 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: + // 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, ???| { var place_value = std.math.pow(u32, 2, @intCast(u32, i)); value += place_value * bit; |