Control Flow
Wysna provides structured control flow primitives: conditionals (if / elif / else), loops (for in, while), and exhaustive pattern matching (match).
Conditional Branching (if / elif / else)
Section titled “Conditional Branching (if / elif / else)”Conditionals evaluate boolean expressions without requiring surrounding parentheses. Use elif for chained branches:
fn assess_score(score: int) -> str { if score >= 90 { return "Excellent" } elif score >= 70 { return "Good" } else { return "Needs Improvement" }}Because if blocks can act as expressions in statement positions, all branches must return compatible types.
Loop Expressions
Section titled “Loop Expressions”for in Loops and Ranges
Section titled “for in Loops and Ranges”Wysna includes first-class range syntax:
0..limit: Half-open range (from0up to, but not including,limit).1..=limit: Inclusive range (from1up to and includinglimit).
fn main() -> unit { # Summing numbers 1 through 10 let mut total = 0 for i in 1..=10 { total = total + i } print("Total:", total)
# Iterating over lists let items = ["apple", "banana", "orange"] for fruit in items { print("Fruit:", fruit) }
# Iterating with index for idx, fruit in enumerate(items) { print(idx, fruit) }}while Loops
Section titled “while Loops”Use while for condition-driven iteration:
fn countdown(start: int) -> unit { let mut current = start while current > 0 { print(current) current = current - 1 } print("Liftoff!")}break and continue
Section titled “break and continue”Inside any loop, use break to terminate early and continue to jump directly to the next iteration:
fn find_first_even(numbers: list[int]) -> int { let mut found = -1 for n in numbers { if n % 2 != 0 { continue } found = n break } return found}