Block expressions
BlockExpression = "{" , { Statement } , "}"
;
Block expressions are a series of statements which result in a value.
Unlike other languages, the tail expression of a block does not impact the result of the expression. Instead,
yield and break statements impact the type. If the block contains no such statements,
the result is unit.
fn main() {
let x: u8 = {
yield 1;
};
}
A block expression is an expression with a block, so it cannot be used directly as an operand. Wrap it in a grouped expression instead:
global G: u8;
fn main() {
let x: u8 = 0;
x = {
yield G;
};
x += ({
yield 1;
}) + 1;
}
yieldcannot be used in the top level block of a function (its body)yieldcannot be used in a loop block. Usebreakinstead