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,24 @@
const expect = @import("std").testing.expect;
// Blocks in Zig are expressions and can be given labels, which are used to yield values.
// Here, we are using a label called `blk`.
// Blocks yield values, meaning they can be used in place of a value.
// The value of an empty block `{}` is a value of the type `void`.
test "labelled blocks" {
const count = blk: {
var sum: u32 = 0;
var i: u32 = 0;
while (i < 10) : (i += 1) sum += i;
break :blk sum;
};
try expect(count == 45);
try expect(@TypeOf(count) == u32);
}
// This can be seen as being equivalent to C's `i++`.
// blk: {
// const tmp = i;
// i += 1;
// break :blk tmp;
// }