ReferenceControlArcReferenceStatements

Statements

Arc statement reference for if/else, return, and for-loop forms inside function bodies

If statements

if condition {
// body
}

if condition {
// body
} else {
// alternative
}

if condition1 {
// body
} else if condition2 {
// alternative
} else {
// fallback
}

Conditions are evaluated for truthiness (true for booleans, non-zero for numerics, non-empty for strings).

Return statements

Functions with return types require explicit return statements.

func compute(x f64) f64 {
    if x < 0 {
        return 0.0 // early return
    }
    return x * 2.0 // required
}

Functions without return types can use return for early exit:

func process() {
    if skip {
        return // early exit
    }
    // more work
}

For loops

Arc supports for loops for iterating over series, counting through ranges, and repeating until a condition is met.

for x := data {
// iterate over a series
}

for i := range(10) {
// count from 0 to 9
}

for condition {
// repeat while condition is truthy
}