Skip to content

Statements

These work as in C, with the truthiness rules of operators. break leaves the nearest loop or switch. continue goes to the next turn of the nearest loop. There is no goto, and no break 2.

function onCreated() {
temp.total = 0;
for (temp.i = 1; temp.i <= 4; temp.i++) {
if (temp.i == 3) {
continue;
}
temp.total += temp.i;
}
echo(temp.total);
// expect: 7
}

Run this example in the playground

A loop or a switch can carry a label. break label; and continue label; then leave or continue that statement from inside an inner one. A label in front of anything else is a compile error.

function onCreated() {
temp.found = 0;
outer: for (temp.a = 1; temp.a <= 3; temp.a++) {
for (temp.b = 1; temp.b <= 3; temp.b++) {
if (temp.a * temp.b == 4) {
temp.found = temp.a @ "x" @ temp.b;
break outer;
}
}
}
echo(temp.found);
// expect: 2x2
}

Run this example in the playground

for (variable : expression) goes through an array, or a list string, once per element. The expression is worked out once, and the loop uses the length the array had at the start. Anything else runs zero times.

function onCreated() {
for (temp.n : {1, 2, 3, 4, 5}) {
if (temp.n == 3) {
continue;
}
if (temp.n == 5) {
break;
}
echo(temp.n);
}
// expect: 1
// expect: 2
// expect: 4
}

Run this example in the playground

The value is worked out once. The cases are tried from the top with loose equality, so case "1": matches switch (1) and text cases ignore case. The first match starts running, and the code falls through to the next case until break. default may stand anywhere and runs when nothing matches. Case values do not have to be constants.

function onCreated() {
switch ("B") {
case "a":
echo("first");
break;
case "b":
echo("second");
case "c":
echo("falls through");
break;
default:
echo("none");
}
// expect: second
// expect: falls through
}

Run this example in the playground

enum STATUS { WAITING, READY, STARTED } makes STATUS.WAITING equal to 0, STATUS.READY equal to 1, and so on. A value restarts the count: { RA, RB = 10, RC } makes RC equal to 11. An enum with no name, enum { A, B }, makes the bare names A and B.

const MAX_ITEMS = 7; makes a constant. At the top of a file it is visible in the whole file. Inside a function it is visible from its line to the end of the block. The value must be a constant expression: literals, other constants, arithmetic, and joining.

Assigning to either is a compile error (E-ASSIGN-CONST).

enum STATUS { WAITING, READY, STARTED }
const MAX_ITEMS = 7;
function onCreated() {
echo(STATUS.STARTED);
// expect: 2
echo(MAX_ITEMS * 2);
// expect: 14
}

Run this example in the playground

with (obj) statement runs the statement with this set to obj. When obj is empty or destroyed, the statement still runs, with this set to a new empty object, and nothing is reported (OQ-LANG-26).

throw expression; raises an error whose message is the text of the expression and whose type is "script". Run-time errors that the engine raises inside a try can be caught too, with type "runtime".

catch (temp.err) receives an object with message, file, line, and type. finally always runs: after the block, after the catch, and when control leaves by return, break, continue, or an error nobody caught.

An error that leaves every try of the call is reported, ends the current function, and gives empty to the caller, which goes on.

function onCreated() {
try {
throw "boom";
} catch (temp.err) {
echo("caught " @ temp.err.message);
} finally {
echo("done");
}
// expect: caught boom
// expect: done
}

Run this example in the playground

new T(args) { init } makes an object of type T. Inside the block, this is the new object. The block needs no ; after it. new[n] and new[rows][columns] make arrays filled with empty values.

function onCreated() {
temp.grid = new[2][3];
echo(temp.grid.size());
// expect: 2
echo(temp.grid[0].size());
// expect: 3
}

Run this example in the playground

{} is allowed only as the whole right side of an assignment: temp.a = {};. It is a compile error anywhere else (E-EMPTY-ARRAY-POSITION), in return {}; or in a call. There are no object literals: {key: value} is E-OBJECT-LITERAL.

Scripts written for the legacy server use a few forms that Bornescript accepts so they compile unchanged (specs language.md §3.10):

  • elseif (c) ... is the same as else if (c) ....
  • Expressions joined by , in a statement (a = 1, b = 2;) run one after the other, each like a statement of its own.
  • An enum or a named function written inside a function body is a declaration of the whole script, as if it stood at the top level.
  • A stray ; before the ) of a for header is ignored.
  • A statement that starts with a name followed by a number or a text calls the function without parentheses: sleep .5;, freezeplayer 3;.
  • =< and => are <= and >=.
  • A call without parentheses may also start with a bare name that ends the statement or is followed by a comma: join gui_common; joins the class with that name and showpoly index, {0, 0}; passes the variable index.
  • A top-level const written after an unnamed enum may reuse the name of one of its members; the const wins.
  • return right before } needs no ;.
  • Statements before the first case of a switch are accepted and never run.

Engine version 0.1.0. Built 2026-11-18.