HomeIndex

Dinky Statements

if, else
If the expr is true, the statement or statements are executed, otherwise the else statements are executed. The 'else' block is optional.
if (expr) statement
if (expr) statement else statement
if (expr) { statements }
if (expr) { statements } else { statements }
For the most part, end of lines are optional.
if (a) doFoo() if (a) doFoo() if (a) { doFoo() } if (a) { doFoo() } else { doBar() } if (a) { doFoo() } else if (b) { doBar() }
while(expr) { ... }
while(expr) { statements } while(expr) statement
While expr is true executes statements
do{ ... }until(expr) | do{ ... }
do { statements } until(expr)
Much like while except expr is checked at the end.
do { statements }
Continually loops through statements. Exclusively used in a threads where they need to run until killed externally.
for(assignment, expr, expr)
This standard c-style for
Initializes a variable then checks a condition, runs the statements, then increments the variable.
for (local i = 1; i < 100; i++) { ... }
for(var = start .. end)
Loops var from start to end
for (local i = 1 .. 100) { ... } for (local i = 100 .. 1) { ... } // Decrements i as it loops for (local i = a .. b) { ... } // Increments i since it doesn't the values of a or b at compile time.
foreach(var in array)
Loops though all the elements of array
foreach(local name in ["Alice", "Bob", "Cindy", "Ted"]) { print(name) }
foreach(var in table)
Loops through all the keys of table
t = { ted = "Ted", alice = "Alice" } foreach (local key in t) { print(t[key]) }
foreach(key, var in table)
Loops through all the keys and values in table
t = { ted = "Ted", alice = "Alice" } foreach (key, value in t) { print("id = ",key, "name = ",value) }
break, continue
breaks out of or continues a for, foreach, while, or until loop
for (i = 1 .. 100) { if (i == 50) break // exit loop when reaching 50 } for (i = 1 .. 100) { if (i > 50) continue print(i) // Only prints numbers from 1 to 50 }
return | return `expr`
Returns from a function passing an optional value
If a function fails to return an expected value, a null is returned. If the function returns a value when none is expected, it is discarded.