Continue statement
Skip the rest of one turn and carry on with the next value.
Simple example
Skip two.
Start1 → 3 · skip 2
Result1
3
const std = @import("std");
pub fn main() !void {
for (1..3 + 1) |number| {
if (number == 2) {
continue;
}
std.debug.print("{any}\n", .{number});
}
}
1 3
Advertisements
Everyday examples
Locker 12 is being repaired. List the available lockers from 11 through 13.
Start11 → 13 · skip 12
Result11
13
const std = @import("std");
pub fn main() !void {
for (11..13 + 1) |locker| {
if (locker == 12) {
continue;
}
std.debug.print("{any}\n", .{locker});
}
}
11 13