Statements
Statements are the basic building blocks of the solus language and every line consists of either an expression or a statement. Statements do not evaluate to a value, meaning they cannot appear on the right hand side of any expression.
var, val
The var statement is used to define a local variable, just like local in Lua or most languages that use it. On the other hand, the val statement is used to denote a value that cannot change, or constant.
Example
var loc = 1;
val con = 2;
con = 3; # Compile Errorif c {} else {}
The if/else statements are used to create branching paths in your code based on a condition. These are fundamental to every programming language in existence. Note that if/else do not only exist as statements, but also as an expression (see Expressions section).
Example
if cond {
return a;
} else {
return b;
}
# or
if cond
return a;
else
return b;for init; condition; post {}
The for loop is a construct that's familiar to any programmer, it's one of the most basic building blocks of control flow next to if/else. The for loop executes the init statement prior to the loop, then uses condition to conditionally execute the body, and finally executed the post statement.
Example
for var x = 0; x < 100; ++x
io.println(x);while c {}
The while statement is used to run a block while a specified condition evaluates to true. This is another fundamental building block of programming languages, and works exactly like it does in others.
Example
var x = 0;
while x < 100 {
io.println(x);
x += 1;
}