Control Flow
The script code is the body of an implicit function with zero parameters, which serves as the entry point of the script.
The body of a function (including the entry-point code) consists of statements that are executed sequentially, except for control flow statements such as loops and conditionals.
// Injects additional APIs from the sub-package "algebra"
// into the current namespace.
use algebra;
let x = 10; // Variable declaration.
foo(x + 20); // Expression statement.
// Simple conditional statement.
if x == 10 {
do_something();
}
// Complex conditional statement.
match x {
10 => {},
20 => {},
else => {},
}
// Infinite loop statement.
loop {
x += 1;
if x > 10 {
break; // Breaks the loop.
}
}
// For loop that iterates through the numeric range from 10 to 19 inclusive.
for i in 10..20 {
dbg(i);
}
// Nested statement block.
{
let inner_var;
func_1();
func_2();
}
// Returning from a function (from the script's main function in this case).
return "end";