Variables

Ola language Variables can have any name which does not start with a number.

Identifier

Variables consist of numbers (0-9), ASCII uppercase and lowercase letters (a-zA-Z), underscores (_). Variables cannot start with a number, and cannot use

fn foo() {
    // declare and ine `_variable`
    u32 _aBC123 = 2;   // identifiers start with "_"
    // u32 0a = 2;  define error, identifiers can't start with number
}

Declaration

Variables need to be declared in order to be used. To avoid variables being undefined, it needs to be initialized at declaration time.

fn foo() {
    // declare and define `a`
    u32 a = 2;
    // redefine `a`
    a = 3;
}

Scope

For security reasons, variable definitions do not support Shadowing. If you need multiple adjacent variables with similar logical meanings, use a variable or type suffix.

Variables differ from constants in that the scope of a variable is limited to the current function itself and global variables are not supported.

Variables in a For-Loop loop are scoped only inside the loop.

Last updated