Variables
Variables can have any name which does not start with a number. Variables are mutable, and always passed by value to functions.
Declaration
Variables need to be declared to be used. Declaration and definition are always combined, so that undefined variables do not exist.
def main():
// declare and define `my_variable`
field my_variable = 2
// redefine `my_variable`
my_variable = 3
return
Shadowing
Shadowing is not allowed.
def main() -> field:
field a = 2
// field a = 3 <- not allowed
for u32 i in 0..5 do
// field a = 7 <- not allowed
endfor
return a
Scope
Function
Functions have their own scope
def foo() -> field:
// return myGlobal <- not allowed
return 42
def main() -> field:
field myGlobal = 42
return foo()
For-loop
For-loops have their own scope
def main() -> u32:
u32 a = 0
for u32 i in 0..5 do
a = a + i
endfor
// return i <- not allowed
return a