BRAIDGROUP
RESEARCH & DEV
9. Documentation

Statements

Statements are the units of execution in Braid. Unlike expressions, statements do not produce values — they perform actions. Braid uses semicolons to terminate most statements.

Expression Statements

Any expression followed by a semicolon is a statement. The expression is evaluated and its value is discarded:

print("Hello");
42;
x + 1;
foo();

Let Declarations

Variable declarations bind a name to a value:

let x = 10;
let name: string = "Braid";
let result = add(1, 2);
let flag = true;
let nothing = nil;

Blocks

A block {} groups multiple statements into a single compound statement:

{
    let a = 1
    let b = 2
    let c = a + b
    print(c)
}

fn main() {
    let x = 10
    if x > 5 {
        print("greater")
    }
}

If / Else Statements

if x > 10 {
    print("x > 10")
}

if x > 20 {
    print("x > 20")
} else {
    print("x <= 20")
}

if x > 20 {
    print("x > 20")
} else if x > 10 {
    print("10 < x <= 20")
} else {
    print("x <= 10")
}

While Statements

let i = 0
while i < 5 {
    print(i)
    i = i + 1
}

// Nested while
let outer = 0
while outer < 3 {
    let inner = 0
    while inner < 2 {
        print("outer=" + outer + " inner=" + inner)
        inner = inner + 1
    }
    outer = outer + 1
}

Return Statements

Return exits the current function, optionally with a value:

fn add(a: int, b: int) -&gt; int {
    return a + b
}

fn check(val: int) -> bool {
    if val > 0 {
        return true
    }
    return false
}

fn log(msg: string) {
    print(msg)
    return    // no value
}

Match Statements

match code {
    200 => print("OK"),
    404 => print("Not Found"),
    500 => print("Server Error"),
    _ => print("Unknown")
}

match x {
    0 => {
        print("x is zero")
    },
    1 => {
        print("x is one")
    },
    _ => {
        print("x is something else")
    }
}

Import Statements

import std.io
import std.math
import std.time
import ui.widget
import ui.layout

Struct Declarations

struct Point {
    x: int
    y: int
}

struct User {
    name: string
    age: int
    email: string
    active: bool
}

Enum Declarations

enum Color {
    Red
    Green
    Blue
}

enum Status {
    OK
    NotFound
    Error
}

Diameter Declarations

diameter temperature: {
    pole hot: {
        return 80.0
    }
    pole cold: {
        return 10.0
    }
}

Statement vs Expression Distinction

Braid follows C-style syntax where statements and expressions are distinct:

CategoryProduces Value?Examples
ExpressionYes42, x + 1, foo()
Expression stmtNo (value discarded)42;, foo();
Let declarationNolet x = 5;
BlockNo{ stmt; stmt; }
IfNoif x { ... }
WhileNowhile x { ... }
ReturnNo (exits function)return x;
MatchNomatch x { ... }
ImportNoimport std.io;