Language reference

Control flow

Conditional branches, loops, selection, and script returns.

01

Conditions

Conditions accept booleans or finite scalar numbers. Zero is false; any other finite scalar is true.

Sun
value = 7;
if value < 0
    disp("negative");
elseif value == 0
    disp("zero");
else
    disp("positive");
end
02

for and while

Range loops evaluate bounds once. Matrix for loops iterate columns; a row vector therefore yields one scalar per iteration.

Sun
total = 0;
for value = 1:5
    total = total + value;
end

while total > 10
    total = total - 1;
end
03

switch

Cases match scalar numbers, booleans, or strings without fall-through. String matching is case-sensitive.

Sun
switch mode
    case "fast"
        disp("Fast mode");
    otherwise
        disp("Default mode");
end
04

Backend status

Support boundary

Loops, conditionals, switch, and return are interpreter-only at the audited commit.