Statements (v0.2.1)

Conditional and control statements for runtime execution.

Latest

Overview

Statements control what a function does step by step. Thrust uses explicit blocks for branches, loops, returns, and control statements.

Clear blocks make error handling easier to follow. They also make it easier to see where a function exits or changes state.

Prefer readable control flow over clever shortcuts, especially in code that handles pointers, files, or memory.

Primary source: syntax/statements/

Syntax Signatures

if ready {
    return 0;
} else {
    return 1;
}

break;
continue;

Behavior and Use

Use early returns for invalid input or error cases when that makes the main path clearer.

Avoid deeply nested conditionals when a small helper function would make the branch easier to understand.

Best Practices

Blocks and Branches

Statements are grouped with braces so control flow is visible.

Loop Control

break and continue only make sense inside loops.

Example

fn classify(n: s32) s32 @public {
    if n < 0 {
        return -1;
    }
    if n == 0 {
        return 0;
    }
    return 1;
}

Back to language reference