The Equal To General Operator is used to assign a value to a variable. It appears in two contexts: during variable creation with the New command to set the initial value, and with the Set command to change an existing variable's value. The value on the right side of Equal To is stored in the variable on the left side.
The short syntax structure uses the = symbol:
NEW DATA TYPE VARIABLE = VALUE
SET VARIABLE = VALUEThe long syntax structure uses the words EQUAL TO:
NEW DATA TYPE VARIABLE EQUAL TO VALUE
SET VARIABLE EQUAL TO VALUEWhen creating a variable with New, Equal To assigns the initial value. The value must match the declared data type.
NEW INT x = 10 // Assigns 10 to variable x
NEW STR name = "Alice" // Assigns "Alice" to variable name
NEW BOOL isActive = TRUE // Assigns TRUE to variable isActive
NEW FLOAT price = 19.99 // Assigns 19.99 to variable priceNEW INT x = 5
NEW INT y = x // Assigns the value of x (5) to y
PRINTLN y // Displays "5"NEW INT sum = 5 + 3 // Assigns result of expression (8) to sum
NEW BOOL isValid = 10 > 5 // Assigns result of comparison (TRUE) to isValid
NEW STR message = "Hello" .. " World" // Assigns concatenated string to message
PRINTLN sum // Displays "8"
PRINTLN isValid // Displays "TRUE"
PRINTLN message // Displays "Hello World"When modifying a variable with Set, Equal To assigns a new value. The variable must already exist and the value must match its data type.
NEW INT counter = 0
PRINTLN counter // Displays "0"
SET counter = 10
PRINTLN counter // Displays "10"
SET counter = 25
PRINTLN counter // Displays "25"NEW INT x = 5
SET x = x + 1 // Assigns x + 1 (6) back to x
PRINTLN x // Displays "6"
SET x = x * 2 // Assigns x * 2 (12) back to x
PRINTLN x // Displays "12"NEW INT counter = 0
SET counter = counter + 1 // Increment by 1
PRINTLN counter // Displays "1"
SET counter = counter - 1 // Decrement by 1
PRINTLN counter // Displays "0"It's important to distinguish between the assignment operator (Equal To / =) and the comparison operator (Is Equal To / ==).
NEW INT x = 5 // EQUAL TO (=) assigns 5 to x
NEW BOOL y = x == 5 // IS EQUAL TO (==) compares x to 5, result is TRUE
PRINTLN x // Displays "5"
PRINTLN y // Displays "TRUE"NEW INT a = 5
NEW INT b = 3
NEW INT result = ( a + b ) * 2 // Assigns ( 5 + 3 ) * 2 = 16
PRINTLN result // Displays "16"NEW STR firstName = "John"
NEW STR lastName = "Doe"
NEW STR fullName = firstName .. " " .. lastName
PRINTLN fullName // Displays "John Doe"NEW INT i = 1
NEW INT sum = 0
WHILE i <= 5
SET sum = sum + i // Add i to sum each iteration
SET i = i + 1 // Increment i
END WHILE
PRINTLN sum // Displays "15"NEW INT x = 5
SET x = 5.0 // Runtime error! Cannot assign Float to Integer variable
SET x = 6 // Correct! Assigning Integer to Integer variableNEW INT x = 5
SET x == 10 // Syntax error! Use = for assignment, not ==
SET x = 10 // Correct! EQUAL TO (=) assigns valueSET x = 10 // Runtime error! Variable x doesn't exist
NEW INT x = 10 // Correct! Create variable firstNEW INT x // Syntax error! Must assign initial value
NEW INT x = 0 // Correct! Initial value assigned with EQUAL TO