For Loops
value as an int, and values remains usable after the loop.
Ranges
Userange for counted loops.
enumerate when you need the index and the value together.
Comprehensions
List and dictionary comprehensions keep their Python shape.Optional Values While Iterating
When a lookup can miss, handleNone inside the loop before using the value.
Mutation While Iterating
Prefer building a new collection when transforming data.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.