Control Flow

ROX provides minimal but sufficient control flow constructs. All control flow is explicit.

Conditionals

if / else

Standard conditional logic. Boolean expressions must be explicit.

if (x > 10) {
    print(['B','i','g','\n']);
} else if (x == 0) {
    print(['Z','e','r','o','\n']);
} else {
    print(['S','m','a','l','l','\n']);
}

Loops

for

ROX has a single loop construct: for. It iterates over a range of numbers.

Syntax:

// Print 0 to 4
for i in range(0, 5, 1) {
    // i is 0, 1, 2, 3, 4
}

To iterate backwards:

// Print 10 down to 1
for i in range(10, 0, -1) {
    // i is 10, 9, ... 1
}

Note: range is a standard built-in function. All 3 arguments are required. Step must not be 0 (compile-time error for literal 0, runtime error otherwise). Negative steps are supported.

Iterating Lists

Use for item in list to iterate over any list[T].

list[int64] nums = [1, 2, 3];
for n in nums {
    print(n, " ");
}

Loop Control

break

Terminates the nearest enclosing loop immediately.

for i in range(0, 10, 1) {
    if (i == 5) {
        break; // Stop at 5
    }
    print(i);
}

continue

Skips the rest of the current iteration and proceeds to the next one.

for i in range(0, 5, 1) {
    if (i % 2 == 0) {
        continue; // Skip even numbers
    }
    print(i);
}