Control Flow
Control flow statements in Tish.
Conditionals
if (cond) stmt
if (cond) stmt else stmtLoops
while (cond) stmt
do stmt while (cond)
for (init; cond; update) stmt
for (let x of arr) stmt
for (const x of arr) stmt- C-style for:
init,cond,updateare optional. - for-of: Iterate over arrays and strings. Use
letfor mutable binding,constfor immutable.
Switch
switch (expr) {
case val1: stmt...
case val2: stmt...
default: stmt
}Return, break, continue
return expr
break
continueError handling
throw expr
try stmt catch (e) stmttypeof and void
typeof expr // returns "number", "string", "boolean", "null", "object", "function"
void expr // evaluates expr, returns nulltypeof null returns "null" in Tish (unlike JavaScript, where typeof null === "object"). Since Tish has no undefined, it uses null as the absence-of-value type, and typeof reflects that.
Blocks
Blocks use braces { } or indentation:
if (x > 0) {
console.log("positive")
} else {
console.log("non-positive")
}
if (x > 0)
console.log("positive")
else
console.log("non-positive")