Docs/Language

Language

Functions and control flow

Declare functions and write predictable branches and loops.

About 10 minVersion: 0.10.1

Functions

Use fn, a parameter list and an optional return type. return exits the current function. Recursion is supported and bounded to 128 VM frames.

flow.orvi
1fn clamp(value: int, minimum: int, maximum: int) -> int {2    if value < minimum {3        return minimum4    } else if value > maximum {5        return maximum6    }7    return value8}910for index in 0..3 {11    print(clamp(index, 1, 2))12}

Conditions require booleans

if and while conditions must evaluate to bool. Values are not implicitly treated as truthy or falsy.

conditions.orvi
1let ready = true23if ready {4    print("ready")5} else {6    print("waiting")7}89let attempts = 010while attempts < 3 {11    attempts = attempts + 112}

for, break and continue

for iterates typed lists and integer ranges. 0..3 excludes 3, while 0..=3 includes it. break exits the closest loop and continue starts its next iteration.

loops.orvi
1for value in [2, 4, 6] {2    if value == 4 {3        continue4    }5    print(value)6}78for index in 1..=3 {9    print(index)10}