mirror of
https://codeberg.org/ziglings/exercises.git
synced 2026-03-28 21:34:52 +00:00
Merge pull request 'emphasize that the end number of a for-loop range is exclusive' (#366) from pebose/exercises:emphasize-for-loop-range into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/366
This commit is contained in:
commit
d5fdfe708c
|
|
@ -1147,7 +1147,7 @@ const exercises = [_]Exercise{
|
||||||
},
|
},
|
||||||
.{
|
.{
|
||||||
.main_file = "095_for3.zig",
|
.main_file = "095_for3.zig",
|
||||||
.output = "1 2 4 7 8 11 13 14 16 17 19",
|
.output = "1 2 4 7 8 11 13 14 16 17 19\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
|
||||||
},
|
},
|
||||||
.{
|
.{
|
||||||
.main_file = "096_memory_allocation.zig",
|
.main_file = "096_memory_allocation.zig",
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@
|
||||||
// 0..10 is a range from 0 to 9
|
// 0..10 is a range from 0 to 9
|
||||||
// 1..4 is a range from 1 to 3
|
// 1..4 is a range from 1 to 3
|
||||||
//
|
//
|
||||||
|
// Crucially, the end value is EXCLUSIVE.
|
||||||
|
//
|
||||||
// At the moment, ranges in loops are only supported in 'for' loops.
|
// At the moment, ranges in loops are only supported in 'for' loops.
|
||||||
//
|
//
|
||||||
// Perhaps you recall Exercise 13? We were printing a numeric
|
// Perhaps you recall Exercise 13? We were printing a numeric
|
||||||
|
|
@ -64,6 +66,12 @@ pub fn main() void {
|
||||||
}
|
}
|
||||||
|
|
||||||
std.debug.print("\n", .{});
|
std.debug.print("\n", .{});
|
||||||
|
|
||||||
|
// Let's also print every number from 1 through 15
|
||||||
|
for (???) |n| {
|
||||||
|
std.debug.print("{} ", .{n});
|
||||||
|
}
|
||||||
|
std.debug.print("\n", .{});
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// That's a bit nicer, right?
|
// That's a bit nicer, right?
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
--- exercises/095_for3.zig 2023-10-03 22:15:22.125574535 +0200
|
--- exercises/095_for3.zig 2026-02-27 19:33:59
|
||||||
+++ answers/095_for3.zig 2023-10-05 20:04:07.272770937 +0200
|
+++ answers/095_for3.zig 2026-02-27 19:33:38
|
||||||
@@ -54,7 +54,7 @@
|
@@ -56,7 +56,7 @@
|
||||||
|
|
||||||
// I want to print every number between 1 and 20 that is NOT
|
// I want to print every number between 1 and 20 that is NOT
|
||||||
// divisible by 3 or 5.
|
// divisible by 3 or 5.
|
||||||
|
|
@ -9,3 +9,12 @@
|
||||||
|
|
||||||
// The '%' symbol is the "modulo" operator and it
|
// The '%' symbol is the "modulo" operator and it
|
||||||
// returns the remainder after division.
|
// returns the remainder after division.
|
||||||
|
@@ -68,7 +68,7 @@
|
||||||
|
std.debug.print("\n", .{});
|
||||||
|
|
||||||
|
// Let's also print every number from 1 through 15
|
||||||
|
- for (???) |n| {
|
||||||
|
+ for (1..16) |n| {
|
||||||
|
std.debug.print("{} ", .{n});
|
||||||
|
}
|
||||||
|
std.debug.print("\n", .{});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user