Skip to main content

Basic statements

In Rell, the fundamental building blocks of programming are encapsulated within basic statements. These statements enable you to perform a wide range of operations, from assigning values to variables to executing functions and controlling program flow.

Assignment statements​

Assignment statements allow you to assign values to variables or data structures. This is a core operation for manipulating data within your program. Examples include:

var x = 0;
var y = 0;
val values = [10, 20, 30];
val i = 1;
val z = 99;

x = 123;
values[i] = z;
y += 15;

print(x); // 123
print(values); // [10, 99, 30]
print(y); // 15

Here, you set the value of x, assign z to an element in the values array, and increment the value of y by 15.

Function call statements​

Function call statements involve invoking functions or procedures to execute specific tasks. For instance:

print('Hello');

In this example, the print function is called, outputting "Hello" to the console.

Return statements​

Return statements are used to exit functions or procedures, optionally returning a value. Examples include:

return;
return 123;

These statements allow you to exit the current function or procedure. The second return statement additionally returns the value 123.

Block statements​

Block statements group multiple statements together within a code block. This aids in organizing code and controlling variable scope. For example:

function calc() = 42;

{
val x = calc();
print(x); // 42
}

Here, a code block is used to encapsulate the assignment of x and the subsequent function call to print.