Statements
Statements in Rell are essential for controlling program flow and data handling. This section explores variable declarations, conditionals, and loops, providing the foundation for building structured and effective Rell programs.
Declare constants with val
and mutable variables with var
. Constants are immutable and can exist outside functions, while variables can be modified within their scope.
Learn Rell's basic statements for assigning values, calling functions, returning values, and grouping code blocks for organized data manipulation and control flow.
Use the if statement for conditional logic. Add optional else blocks and chain conditions with else-if for more complex logic. It can also be used as an expression to return values conditionally.
The when statement allows multi-way branching, similar to switch in other languages. It supports multiple cases, complex conditions, and can be used as an expression or translated to SQL CASE WHEN ... THEN.
Control loops with for, while, break, and continue statements. The for loop iterates over ranges or collections, while the while loop continues as long as a condition is true. Use break to exit loops early and continue to skip to the next iteration.