Life is not a problem to be solved, but a reality to be experienced.
— Søren Kierkegaard
Control Flow
NAME wyzer-control-flow - Branching and iteration constructs
DESCRIPTION
Wyzer provides if expressions and while/for loops. Control flow constructs evaluate to values.
SYNOPSIS: CONDITIONALS
let number = if condition { 5 } else { 6 };
if ptr != null && ptr.val > 0 {
// ...
}
CONDITIONAL DETAILS
ifexpressions: Evaluates to the last expression of the executed block. Both branches must return identical types.- Short-circuiting: Logical AND (
&&) and OR (||) evaluate left-to-right and short-circuit.
SYNOPSIS: LOOPS
var count = 0;
while count < 3 {
count = count + 1;
}
for item in collection {
io::println(f"Item: {item}");
}
LOOP DETAILS
while: Executes block while condition evaluates totrue.for ... in: Iterates over an iterator or collection.
SYNOPSIS: EARLY RETURNS
fn find_early(x: u32) -> bool {
if x == 5 {
return true;
}
false
}
RETURN DETAILS
return: Immediately halts function execution and returns the specified value.- Implicit return: If a block has no trailing semicolon, the final expression is implicitly returned.