my ziglings
0

Configure Feed

Select the types of activity you want to include in your feed.

dev.1711 - switched to multi-object-for-loops

Chris Boesch (Feb 21, 2023, 9:43 PM +0100) e7326dc5 f9b3d508

+18 -16
+3 -2
README.md
··· 42 42 43 43 ```bash 44 44 $ zig version 45 - 0.11.0-dev.1650+xxxxxxxxx 45 + 0.11.0-dev.11711+xxxxxxxxx 46 46 ``` 47 47 48 48 Clone this repository with Git: ··· 82 82 83 83 ### Version Changes 84 84 85 - Version-0.11.0-dev.1650+xxxxxxxxx 85 + Version-0.11.0-dev.11711+xxxxxxxxx 86 + * *2023-02-21* zig 0.11.0-dev.1711 - changes in `for loops` - new: Multi Object For Loops + Struct-of-Arrays 86 87 * *2023-02-12* zig 0.11.0-dev.1638 - changes in `std.Build` cache_root now returns a directory struct 87 88 * *2023-02-04* zig 0.11.0-dev.1568 - changes in `std.Build` (combine `std.build` and `std.build.Builder` into `std.Build`) 88 89 * *2023-01-14* zig 0.11.0-dev.1302 - changes in `@addWithOverflow` (now returns a tuple) and `@typeInfo`; temporary disabled async functionality
+1 -1
build.zig
··· 8 8 // When changing this version, be sure to also update README.md in two places: 9 9 // 1) Getting Started 10 10 // 2) Version Changes 11 - const needed_version = std.SemanticVersion.parse("0.11.0-dev.1650") catch unreachable; 11 + const needed_version = std.SemanticVersion.parse("0.11.0-dev.1711") catch unreachable; 12 12 13 13 const Exercise = struct { 14 14 /// main_file must have the format key_name.zig.
+6 -5
exercises/016_for2.zig
··· 1 1 // 2 - // For loops also let you store the "index" of the iteration - a 3 - // number starting with 0 that counts up with each iteration: 2 + // For loops also let you use the "index" of the iteration, a number 3 + // that counts up with each iteration. To access the index of iteration, 4 + // specify a second condition as well as a second capture value. 4 5 // 5 - // for (items) |item, index| { 6 + // for (items, 0..) |item, index| { 6 7 // 7 8 // // Do something with item and index 8 9 // ··· 23 24 // Now we'll convert the binary bits to a number value by adding 24 25 // the value of the place as a power of two for each bit. 25 26 // 26 - // See if you can figure out the missing piece: 27 - for (bits) |bit, ???| { 27 + // See if you can figure out the missing pieces: 28 + for (bits, ???) |bit, ???| { 28 29 // Note that we convert the usize i to a u32 with 29 30 // @intCast(), a builtin function just like @import(). 30 31 // We'll learn about these properly in a later exercise.
+1 -1
exercises/038_structs2.zig
··· 44 44 // it do and why? 45 45 46 46 // Printing all RPG characters in a loop: 47 - for (chars) |c, num| { 47 + for (chars, 0..) |c, num| { 48 48 std.debug.print("Character {} - G:{} H:{} XP:{}\n", .{ 49 49 num + 1, c.gold, c.health, c.experience, 50 50 });
+1 -1
exercises/047_methods.zig
··· 86 86 aliens_alive = 0; 87 87 88 88 // Loop through every alien by reference (* makes a pointer capture value) 89 - for (aliens) |*alien| { 89 + for (&aliens) |*alien| { 90 90 91 91 // *** Zap the alien with the heat ray here! *** 92 92 ???.zap(???);
+1 -1
exercises/058_quiz7.zig
··· 239 239 // We'll often want to find an entry by Place. If one is not 240 240 // found, we return null. 241 241 fn getEntry(self: *HermitsNotebook, place: *const Place) ?*NotebookEntry { 242 - for (self.entries) |*entry, i| { 242 + for (&self.entries, 0..) |*entry, i| { 243 243 if (i >= self.end_of_entries) break; 244 244 245 245 // Here's where the hermit got stuck. We need to return
+1 -1
exercises/063_labels.zig
··· 106 106 const meal = food_loop: for (menu) |food| { 107 107 108 108 // Now look at each required ingredient for the Food... 109 - for (food.requires) |required, required_ingredient| { 109 + for (food.requires, 0..) |required, required_ingredient| { 110 110 111 111 // This ingredient isn't required, so skip it. 112 112 if (!required) continue;
+1 -1
exercises/075_quiz8.zig
··· 102 102 end_of_entries: u8 = 0, 103 103 104 104 fn getEntry(self: *HermitsNotebook, place: *const Place) ?*NotebookEntry { 105 - for (self.entries) |*entry, i| { 105 + for (&self.entries, 0..) |*entry, i| { 106 106 if (i >= self.end_of_entries) break; 107 107 if (place == entry.*.?.place) return &entry.*.?; 108 108 }
+3 -3
patches/patches/016_for2.patch
··· 1 - 27c27 2 - < for (bits) |bit, ???| { 1 + 28c28 2 + < for (bits, ???) |bit, ???| { 3 3 --- 4 - > for (bits) |bit, i| { 4 + > for (bits, 0..) |bit, i| {