Control flow¶
Conditional statements¶
Conditional statements are used to execute code based on a condition. In Radon,
the if statement is used to execute code if a condition is true. The else
statement is used to execute code if the condition is false. The elif
statement is used to execute code if the condition is false and another
condition is true. The else statement is optional.
| conditional-statements.rn | |
|---|---|
Switch statement¶
The switch statement matches an expression against one or more case values. The first matching case runs; default runs when no case matches.
| switch.rn | |
|---|---|
Multi-line case body¶
When a case body needs more than one statement, wrap it in { }:
| switch-block.rn | |
|---|---|
fallthrough¶
fallthrough causes execution to continue into the next case body without re-checking its condition:
| fallthrough.rn | |
|---|---|
fallout¶
fallout immediately exits the switch block, similar to break in a loop:
| fallout.rn | |
|---|---|
Assert statement¶
assert takes a condition and an optional message. If the condition is falsy the program raises an error with the message.
assert can also be used as an expression — it returns the asserted value on success:
Catching a failed assertion:
| assert-catch.rn | |
|---|---|
Del statement¶
del removes one or more variables from the current scope. Accessing a deleted name afterwards raises an error.
| del.rn | |
|---|---|
del also works on indexed targets: