You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
841 B
Zig
34 lines
841 B
Zig
4 years ago
|
//
|
||
|
// The last two exercises were functionally identical. Continue
|
||
|
// expressions really show their utility when used with 'continue'
|
||
|
// statements!
|
||
|
//
|
||
|
// Example:
|
||
|
//
|
||
4 years ago
|
// while (condition) : (continue expression) {
|
||
4 years ago
|
//
|
||
4 years ago
|
// if (other condition) continue;
|
||
4 years ago
|
//
|
||
4 years ago
|
// }
|
||
|
//
|
||
4 years ago
|
// The "continue expression" executes every time the loop restarts
|
||
|
// whether the "continue" statement happens or not.
|
||
4 years ago
|
//
|
||
|
const std = @import("std");
|
||
|
|
||
|
pub fn main() void {
|
||
|
var n: u32 = 1;
|
||
|
|
||
|
// I want to print every number between 1 and 20 that is NOT
|
||
|
// divisible by 3 or 5.
|
||
4 years ago
|
while (n <= 20) : (n += 1) {
|
||
4 years ago
|
// The '%' symbol is the "modulo" operator and it
|
||
|
// returns the remainder after division.
|
||
4 years ago
|
if (n % 3 == 0) ???;
|
||
|
if (n % 5 == 0) ???;
|
||
4 years ago
|
std.debug.print("{} ", .{n});
|
||
|
}
|
||
|
|
||
|
std.debug.print("\n", .{});
|
||
|
}
|