Statements
Local Declarations
Str s Str s := "hello" s := "hello" list := [0, 1, 2]
See docLang for details.
If/Else
if (cond) doIt if (cond) doIt else dontDoIt if (cond1) do1 else if (cond2) do2 else do3
See docLang for details.
While
while (cond)
doSomething
while (x)
{
if (y) continue
if (z) break
doSomething
}
See docLang for details.
For
for (i:=0; i<3; ++i)
echo(i)
for (;;)
{
if (y) continue
if (z) break
doSomething
}
See docLang for details.
Switch
switch (method)
{
case "head":
case "get":
serviceGet
case "post":
servicePost
default:
serviceBadMethod
}
Note you don't use the break statement in a switch - it is implied. See docLang for details.
Throw
throw ArgErr()
throw Err("something bad happened")
See docLang for details.
Try/Catch
try
{
doSomething
}
catch
{
echo("any err thrown")
}
try
{
doSomething
}
catch (IOErr e)
{
e.trace
}
try
doSomething // single statement
catch (IOErr e)
e.trace // single statement
try
{
doSomething
}
catch (IOErr e)
{
handleIOErr(e)
}
catch (ArgErr e)
{
throw e // rethrow
}
catch
{
e.trace // anything else
}
See docLang for details.
Try/Finally
try
{
doSomething
}
finally
{
cleanup
}
try
doSomething // single statement
finally
cleanup // single statement
try
{
doSomething
}
catch (Err e)
{
e.trace
}
finally
{
cleanup
}
See docLang for details.
