Variables & Constants
XCX 4.4.1 Variables and Constants
Variable Declarations
Variables are declared using the type: name = value; syntax.
Variables can also be declared without an initial value, in which case they take the default value for their type (e.g., 0 for i, "" for s).
Multiple Variable Declarations
Basic types support declaring multiple variables of the same type in a single statement, separated by commas. Each variable can optionally have its own initializer:
NOTE:
A trailing initializer binds only to the last declared name. In the
example above, first and middle take the type default ("") and only
last receives "Doe". To set several variables in one statement, give
each its own initializer: s: a = "x", b = "y";.
Reassignment
Once declared, variables can be reassigned using the = operator.
Constants
Constants are declared using the const keyword. They must be initialized at declaration and cannot be changed afterwards.
No Variable Shadowing
XCX does not support variable shadowing. Declaring a variable with the same name in any scope - including a nested block - is a compile-time error (RedefinedVariable).
If you need to change a value inside a block, use reassignment instead of redeclaration: