This commit is contained in:
2026-01-19 05:43:29 +09:00
parent 40f41a4fd0
commit 0f6fddd794
36 changed files with 1724 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
const expect = @import("std").testing.expect;
// Like `return`, `break` accepts a value. This can be used to yield a value from a loop.
// Loops in Zig also have an `else` branch, which is evaluated when the loop is not exited with a `break`.
fn rangeHasNumber(begin: usize, end: usize, number: usize) bool {
var i = begin;
return while (i < end) : (i += 1) {
if (i == number) {
break true;
}
} else false;
}
test "while loop expression" {
try expect(rangeHasNumber(0, 10, 3));
}