Control Flow
Jiang separates control-flow statements from expressions that produce values. Blocks, if, and switch can produce values; return, throw, break, and continue do not continue normally.
Blocks
Section titled “Blocks”A block’s value comes from its final tail expression. Without a tail expression, the block value is ().
An if condition is followed directly by a block. As a statement, else may be omitted:
As an expression, if must include else and both branches must produce compatible values:
Statement-style branches can still include else:
switch
Section titled “switch”switch matches patterns and can produce a value:
Branches may use a block:
break exits the current loop and continue starts the next iteration:
for in
Section titled “for in”for pattern in expr iterates arrays, slices, and other iterable values:
Tuple destructuring is a separate statement inside the loop:
Ranges use start..end:
guard is used for early exit while carrying successful bindings into the following scope:
The else block must be non-empty and end in return, break, continue, or throw.
defer runs when the current block exits:
Use defer expr; for a single operation or defer { ... } for several operations.
try catch
Section titled “try catch”Use catch { ... } when only a fallback value is needed:
Bind the error after catch when the handler needs it. The binding type is inferred from E:
Write the type explicitly as catch Error err { ... } when it improves clarity. Parenthesized bindings,
such as catch (err) { ... }, are also accepted. The handler is always a block, and its tail expression
is the fallback value.