Skip to main content
Sifr keeps Python’s readable loop syntax while enforcing ownership and type rules at compile time. Iteration is usually borrowed: you can loop over a collection without consuming it.

For Loops

The loop body sees each value as an int, and values remains usable after the loop.

Ranges

Use range for counted loops.
Use enumerate when you need the index and the value together.

Comprehensions

List and dictionary comprehensions keep their Python shape.
The result type is checked from the expression and the declared binding.

Optional Values While Iterating

When a lookup can miss, handle None inside the loop before using the value.

Mutation While Iterating

Prefer building a new collection when transforming data.
Mutating a collection while iterating over it is a place where ownership rules matter. Keep mutation outside the loop, or write into a separate result collection.
If you know Python, this is stricter by design. Mutating the collection you are iterating over is an ownership constraint the compiler can reject instead of a runtime surprise.

Next Steps

Values and Collections

Review the collection types that loops work with.

Ownership and Mutability

Learn when mutation needs mut, own, or own mut.