Control structures are identical to those of JavaScript. Braces can be omitted when the block contains a single statement.
if (condition) {
// ...
}
else if (otherCondition) {
// ...
}
else {
// ...
}The condition is false for undefined, null, false, 0, NaN and the empty string.
while (condition) {
// ...
}do {
// ...
} while (condition);for (var i = 0; i < 10; i++) {
// ...
}
// Each part is optional, a missing condition is always true
for (;;) {
// ...
}switch (value) {
case 1:
case 2:
// ...
break;
case f(1):
case 3 / 6 + 8 * f(2):
// ...
// Without break, execution continues into the next case
default:
// ...
}Cases are arbitrary expressions, compared with ==. The default case must be the last one.
break leaves the enclosing loop or switch, continue moves to the next iteration of the enclosing loop (including from within a switch or a try block).
return leaves the current function. At the main level of a script, return value; stops the script's execution, and the application retrieves the value.
See Errors.