Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Control flow

Control flow decides which code runs, when it runs, and how often it runs.

Indent blocks consistently with either spaces or tabs throughout each file. Mixing the two in structural indentation is a compile error, including when different lines use different styles. Spaces and tabs inside strings, comments, and continuation alignment do not determine the file's indentation style.

Acton does not have a Rust-style match expression. Use if/elif/else for branching, and combine that with optionals or exceptions when the question is about absence or failure.

Start with these three everyday tools:

Loops also support a few extra tools:

  • break to stop the loop early
  • continue to skip to the next iteration
  • else to run code after a loop finishes normally, without a break

If you are new to programming, start with if, for, and while and treat loop else as optional. Most code uses the first three tools far more often.

for n in range(5):
    if n == 2:
        continue
    if n == 4:
        break
    print(n)
else:
    print("finished without break")

Loop else is tied to break, not to "zero iterations". It runs whenever the loop finishes normally, which makes it useful for search-style logic but easy to misread if used casually.

Acton also has actor-specific control patterns such as after. Those matter once you start thinking about actors, timers, and concurrency.