mirror of
https://github.com/ziglang/zig.git
synced 2024-11-30 09:02:32 +00:00
18 lines
371 B
Zig
18 lines
371 B
Zig
const expect = @import("std").testing.expect;
|
|
|
|
test "while else" {
|
|
try expect(rangeHasNumber(0, 10, 5));
|
|
try expect(!rangeHasNumber(0, 10, 15));
|
|
}
|
|
|
|
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
|