Language / Blocks and statements

Blocks and statements

Blocks ({ ... }) group statements and introduce a new scope.

Full reference: flow blocks statements.

Notes#

Example: scope boundaries#

fn main () -> int {
  let x: int = 1;
  {
    let y: int = 2;
    if x + y != 3 {
      return 1;
    }
  }
  // `y` is not in scope here.
  return 0;
}

See also#

Source repository · Edit this page · View Markdown