Loops/For with a specified step: Difference between revisions
Zig version with for-loop added
(demonstrated decrementing with steps as well) |
(Zig version with for-loop added) |
||
Line 3,078:
=={{header|Zig}}==
<syntaxhighlight lang="zig">
const std = @import("std");
pub fn main() !void {
Line 3,085 ⟶ 3,086:
while (i < 10) : (i += 2)
try stdout_wr.print("{d}\n", .{i});
}
===With for-loop===
<syntaxhighlight lang="zig">
const std = @import("std");
const stdout = @import("std").io.getStdOut().writer();
pub fn main() !void {
for (1..10) |n| {
if (n % 2 == 0) continue;
try stdout.print("{d}\n", .{n});
}
}
</syntaxhighlight>
{{out}}
<pre>
1
3
5
7
9
</pre>
|