Variables
Variables are
Declare variables
Brasa is a statically typed language, so you have to explicitly set the type when declaring a variable.
Variables and data types
int x := 10;
Notice, the use of semicolon
;. It determines the end of a statement. Also, notice the use of:=rather than the standard=as the assignment operator defined in common languages.
Brasa has four primitive types:
- int (1, -3, ...)
- real (3.14, 2.71828, -3.0, ...)
- logico (verdadeiro or falso)
- texto ("string", "This is a text", ...)
It also supports nullable by using ? in front of a type:
int? index := nulo;
For this particular example, you can assign an integer or nulo to denote the abscence of value.
You should use this when a variable doesn't have a meaningfull value at its declaration time yet.
You can also add a const modifier to make assignments impossible
const int x := 10;
x := 30; // error
For more info, check Variables Reference