const c = blk: {
if (a > b) {
// some processes
break :blk 100;
} else {
// some processes
break :blk 200;
}
};
In rust, if is an expression which can direct return the final value.
But in Zig, what I can do is:
var c: i32 = undefined;
if (a > b) {
// some processes
c = 100;
} else {
// some processes
c = 200;
}
Either I have to change const to var, or I can do is using a block with an additional label and break value to it.
Is there a better way to rewrite this?