A block is the basic unit for structured control flow. It holds a ordered collection of statements that are executed in order, starting with the first statement. It may also accumulate its own temporary, local state.
Control flow statements may be used to direct the flow of execution from one block to another or manage block state:
- with blocks. Focus a block's work on some complex value.
- if .. elif .. else. Choose which block to execute based on evaluating one or more conditional expressions.
- pattern matching. Choose which block to execute based on which pattern first matches some value
- while or loop. Repeatedly execute some block while certain conditional expressions are true.
- each iteration. Repeatedly perform some block for each every value in some iterated sequence.
- exception handling. Support different control flows for successful processing vs. thrown exceptions.