Version: 1.1.0

Compound statements

Compound statements own an indented block: if, for, while, try, with, def, fn, struct, and trait.

Essentials

  • The header ends with a colon.
  • The block is indented further than the header.
  • try pairs with except and optionally else or finally.
  • with runs cleanup even when the block returns.
  • Nested compound statements are fine until the indent becomes the story.

Example

def main() raises:
    with open("notes.txt", "r") as f:
        print(f.read())

Keep in mind

Extract a function when a compound statement no longer fits on one screen.