Loops/Do-while: Difference between revisions

add Zig example with hint of when do-while is not necessary
No edit summary
(add Zig example with hint of when do-while is not necessary)
Line 3,152:
1 2 3 4 5 6
</pre>
 
=={{header|Zig}}==
<lang zig>const std = @import("std");
 
pub fn main() !void {
var a: u8 = 0;
// no do-while in syntax, trust the optimizer to do
// correct Loop inversion https://en.wikipedia.org/wiki/Loop_inversion
// If the variable `alive` is independent to other variables and not in
// diverging control flow, then the optimization is possible in general.
var alive = true;
while (alive == true or a % 6 != 0) {
alive = false;
a += 1;
try std.io.getStdOut().writer().print("{d}\n", .{a});
}
}</lang>
 
{{omit from|GUISS}}
37

edits