Control Flow

Conditionals, loops, and branching in Reox.

If/Else Statements

Use if, else if, and else for conditional branching. Conditions must be boolean expressions (no implicit conversion).

let score: int = 85;

if score >= 90 {
    print("Excellent!");
} else if score >= 70 {
    print("Good job!");
} else {
    print("Keep trying!");
}

While Loops

Execute a block repeatedly while a condition is true.

let mut count: int = 0;

while count < 5 {
    print(count);
    count = count + 1;
}

// Output: 0, 1, 2, 3, 4

For Loops

Iterate over arrays and ranges with for..in.

// Iterate over array
let items = ["apple", "banana", "cherry"];

for item in items {
    print(item);
}

// Iterate over range
for i in 0..10 {
    print(i);
}

Break and Continue

Use break to exit a loop early, and continue to skip to the next iteration.

for i in 0..100 {
    if i == 5 {
        break;  // Exit loop
    }
    if i % 2 == 0 {
        continue;  // Skip even numbers
    }
    print(i);
}
// Output: 1, 3

Logical Operators

Combine conditions with and, or, and not.

let age: int = 25;
let hasLicense: bool = true;

if age >= 18 and hasLicense {
    print("Can drive");
}

if age < 13 or age > 65 {
    print("Discount available");
}

if not hasLicense {
    print("Get a license first");
}