Conditional Overview
If, else, comparisons, boolean conditions, and while loops in Nexus 1.3.
Overview
Nexus uses standard if / else if / else for conditional branching and while for looping. Conditions must evaluate to bool (or types that can be implicitly treated as boolean).
Logical operators (&&, ||, !) are not yet implemented in 1.3. For compound conditions, nest if statements or refactor your logic until 1.4.
No for loops exist yet, iteration must use while. Full for (including range-based) and enhanced while support (with break/continue improvements) are planned for 1.4.
Comparisons & Equality
Nexus supports the usual comparison operators for primitives:
==: equality!=: inequality<,<=,>,>=: ordering (on numeric types)
Equality == and inequality != work on integers, floats, booleans, and strings (UTF-8 byte-wise comparison). No implicit conversions occur during comparison.
i32 a = 42;
i32 b = 10;
bool eq = (a == 42); /* true */
bool ne = (b != 42); /* true */
bool gt = (a > b); /* true */
If / Else If / Else
Parentheses around the condition are required. Braces are required for multi-statement blocks (single statements may omit them, but braces are recommended for clarity).
i32 test = 5;
if (test == 5) {
Printf("test");
}
if (test != 6) {
test++;
Printf("updated test : {test}");
} else {
Print("equal");
}
if (test == 7) {
Printf("somehow 7");
} else if (test == 6) {
Print("6 == {test}");
} else {
return true;
}
While Loops
while loops run as long as the condition is true. The condition is checked before each iteration. Currently experimental in 1.3 use with care; full stabilization + break/continue expected in 1.4.
i32 test = 5;
while (test < 10) {
test++;
Printf("test is now {test}");
}
For counting or ranging over values right now, just use while with manual increment/decrement. Better iteration syntax coming in 1.4.