Statements

if, for, blocks, then, otherwise

Notch statements are evaluated for their side effects. The two main statement forms are if and for.

if statement

if true print('foo') else print('bar') end

The else branch is optional:

if true print('foo') end

for statement

for iterates over any iterable: lists, strings (per-character), maps.

for x in 'foo' print(x) end

Prints f, o, o on separate lines.

The optional index clause binds the iteration index:

for x in 'foo' index i print(i) print(x) end

Outside the loop, the loop variable is <undefined>:

for x in 'foo' index i print(i) print(x) end
print(x)

Block forms

A block is a sequence of statements terminated by end. The if and for forms above use blocks.

then and otherwise

The single-expression variants are:

stmt-then    := block | 'then' expr
stmt-fallback := 'else' block 'end' | 'otherwise' expr

These are planned for parser implementation; the block form is shipped today.

See also

  • Operators for the expression form of conditionals (when).
  • Closures for inline functions.