#expression if
1 messages · Page 1 of 1 (latest)
x = if (condition) 1 else 2
neat thanks
Switches and blocks can also return expressions
const x = switch (thing) {
a => 1,
b => 1000,
};
const y = blk: {
doThing(&z);
break :blk z;
};
also loops:
const index: ?T = for (items) |elem| {
if (std.meta.eql(elem, key)) break elem;
} else null;