Variables

To define a variable, type the data type of the variable followed by a white space, the name of the variable and a semicolon.

Such a variable can be initialized later, but it can also be initialized in the declaration itself. Of course, the value of the expression must be of the same data type as the variable.

Both cases of variable declaration and initialization are shown below:

dataType variable;
...
variable = expression;
dataType variable = expression;

Example 67. Variables

int a;
a = 27;
int b = 32;
int c = a;

Constants

Adding const modifier to a variable declaration will protect it from being accidentally modified later in the code. CTL validator will report an error on any attempt to assign a value to a constant. Note that modifications via function calls, e.g. clear(), are not checked.

Example 68. Constants

const integer INT_CONSTANT = 10;
const string MY_ID = "ABC";
const string[] LIST_CONSTANT = ["a", "b", "c"];

INT_CONSTANT = 11; // error
MY_ID = ""; // error
LIST_CONSTANT[0] = "x"; // error
clear(LIST_CONSTANT); // not checked