Statements
Inside function bodies and closure blocks { … }, you can use the following statements.
Forms
| Statement | Syntax sketch |
|---|---|
| Return | return expr [ ';' ] |
| Fail | fail skip ( expr ) or fail stop ( expr ) (strategy + cause) |
| Const | const name = expr ';' |
| Let | let name = expr ';' |
| Assign | name = expr ';' |
| If / else | if '(' cond ')' block ( else if ... )* [ else block ] |
| While | while '(' cond ')' block |
| For | for '(' binding in iterable ')' block |
| Do-while | do block while '(' cond ')' |
| Break | break [ expr ] [ ';' ] |
| Continue | continue [ ';' ] |
| Expression | expr ';' |
A semicolon may be omitted in some positions (e.g. return before }).
Blocks
A block is { zero or more statements }.
Module scope vs function body
At namespace scope, name = expr without const or let declares a module-level constant (this is how flow = … is written). Inside functions and closures, use const, let, or assignment statements as above.