Version: 1.1.0

Control flow

Conditions and loops use a colon and an indented block. if, elif, else, for, and while are the whole set.

Essentials

  • if tests a Bool. There is no implicit truthiness for integers or strings.
  • for item in collection walks an iterator.
  • range produces a half-open span of integers.
  • break and continue leave or skip a loop iteration.
  • A compile-time comptime if deletes the unused branch before runtime.

Example

def main():
    for n in range(5):
        if n % 2 == 0:
            print(n)

Keep in mind

Prefer for over index loops unless you truly need the index. See ranges for the bounds.