-
Notifications
You must be signed in to change notification settings - Fork 5
Variables
Variables may either be global(can be accessed anywhere in the file) or local(can only be accessed inside the declared scope or inner scopes). To declare a variable, you must specify the name and type:
- Local variable:
let myVariable: i32 = 23;
- Global variable:
global myVariable: i32 = 23;
The type of a variable may not be void
as values are not allowed to have this type.
For non-global variables, an initialization value is not required so they can be left unitialized until needed. The initialization value of a global variable must be a constant value.
Note: Make sure not to include ()
after the variable name as this will make the compiler assume you are attempting to define a function.
To use a variable, simply type the name of the variable:
myVariable
This will return the value of the variable or, will allow you to change the value of the variable if used as the left hand side of an assignment operation.
Wiki created by @solar-mist and @Kami