Local variables
Local variables in Move are lexically (statically) scoped. New variables are introduced with the keyword let
, which will shadow any previous local with the same name. Locals are mutable and can be updated both directly and via a mutable reference.
Syntax:
Variables must be assigned before use
Move's type system prevents a local variable from being used before it has been assigned.
Valid variable names
Variable names can contain underscores _
, letters a
to z
, letters A
to Z
, and digits 0
to 9
. Variable names must start with either an underscore _
or a letter a
through z
. They cannot start with uppercase letters.
Multiple declarations with tuples
let
can introduce more than one local at a time using tuples. The locals declared inside the parenthesis are initialized to the corresponding values from the tuple.
Underscore for unused variables
In Move every variable must be used (otherwise your code won't compile), hence you can't initialize one and leave it untouched. Though you have one way to mark variable as intentionally unused - by using underscore _
.
Last updated