aboutsummaryrefslogtreecommitdiff
path: root/16_for2.zig
diff options
context:
space:
mode:
authorDave Gauer <dave@ratfactor.com>2021-02-09 18:36:57 -0500
committerDave Gauer <dave@ratfactor.com>2021-02-09 18:36:57 -0500
commit55ad7c32f2d534b1fbd438204d21738f958c51a5 (patch)
tree16be4b53193105a759b3eec25be5e664d41c428d /16_for2.zig
parentcf0920de31e9b5f3c5ba6de19a1b4c8d0c58b907 (diff)
downloadziglings-55ad7c32f2d534b1fbd438204d21738f958c51a5.tar.gz
ziglings-55ad7c32f2d534b1fbd438204d21738f958c51a5.tar.bz2
ziglings-55ad7c32f2d534b1fbd438204d21738f958c51a5.tar.xz
ziglings-55ad7c32f2d534b1fbd438204d21738f958c51a5.zip
Moved exercises to exercises because exercises
Diffstat (limited to '16_for2.zig')
-rw-r--r--16_for2.zig33
1 files changed, 0 insertions, 33 deletions
diff --git a/16_for2.zig b/16_for2.zig
deleted file mode 100644
index 0a62a1a..0000000
--- a/16_for2.zig
+++ /dev/null
@@ -1,33 +0,0 @@
-//
-// For loops also let you store the "index" of the iteration - a
-// 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 {
- // Let's store the bits of binary number 1101 in
- // 'little-endian' order (least significant byte first):
- const bits = [_]u8{ 1, 0, 1, 1 };
- 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:
- for (bits) |bit, ???| {
- var place_value = std.math.pow(u32, 2, @intCast(u32, i));
- value += place_value * bit;
- }
-
- std.debug.print("The value of bits '1101': {}.\n", .{value});
-}