Skip to main content

Statements

Grammar​

program = { statement } ;
statement = assignment | exprStmt | block | ifStmt | forStmt | ";" ;
assignment = identifier "=" expression ";" ;
exprStmt = expression ";" ; (* result discarded, e.g. a builtin call *)
block = "{" { statement } "}" ;
ifStmt = "if" "(" expression ")" statement [ "else" statement ] ;
forStmt = "for" "(" identifier "=" expression ";"
expression ";"
identifier "=" expression ")" statement ;
expression = see the precedence table under Operators ;
call = identifier "(" [ expression { "," expression } ] ")" ;

Assignment​

name = expression; is a statement, not an expression. So a = b = 1;, if (x = 5) and f(x = 1) are all errors. There's no compound assignment (+=) and no ++/--. Write i = i + 1;.

Expression statements​

Any expression followed by ; is a statement, and its value is thrown away. That's how a builtin is called for its effect: WindowMinimize(w);. The Bool most builtins return is ignored unless you capture it: ok = FileDelete(p);.

if / else​

The parentheses around the condition are required. The branch is a single statement or a { } block. else if is just an else whose statement is another if, so chains work. A dangling else belongs to the nearest if. Use braces when that's ambiguous.

n = MathRandom(1, 100);
if (n < 10) {
size = "small";
} else if (n < 50) {
size = "medium";
} else {
size = "large";
}
if (n == 42) UtilityPrint("the answer"); // single-statement branch, no braces

for​

for (init; condition; step) body. All three parts are required. init and step must each be a single name = expression assignment, with no comma-separated lists and no bare calls. condition is any expression and is checked before each pass, including the first. step runs after each pass.

for (i = 10; i > 0; i = i - 2) {
UtilityPrint(StringFormat("{0}", i, "")); // 10 8 6 4 2
}

It's the only loop. There's no while, do, break, continue or for x in …. The standard substitutes are under Control-flow idioms.

Blocks​

{ ... } groups statements anywhere a single statement is expected, including at the top level. It doesn't open a new variable scope.