Another do-while loop:
test "do-while" {
var i: u8 = 'a';
var result: std.ArrayListUnmanaged(u8) = .empty;
defer result.deinit(std.testing.allocator);
while (do_blk: {
i += 1;
try result.append(std.testing.allocator, i);
break :do_blk i != 'd';
}) {}
try std.testing.expectEqualStrings("bcd", result.items);
}
with
– Szepub inline fn do(work: void, @"while": bool) bool { _ = work; return @"while"; }you can writewhile(do({ body-here }, condition)) {}even auto formats so that the condition is the last line and zls inlay hints kind-of make sensePerhaps I am being overly cautious, but this implementation relies somewhat on the left-to-right evaluation order of expressions, and I have not yet confirmed this in the documentation.
– npc1054657282https://ziggit.dev/t/does-zig-guarantee-left-to-right-order-of-evaluation/2684
– Sze