Compile-Time Loop Unrolling
Expand loops with @parameter for.
Loops the Compiler Expands
Loop unrolling means the compiler writes out each iteration as straight-line code, removing the loop's counting and branching overhead. ⚙️
The @parameter for Decorator
Put @parameter on a for loop whose range is known at compile time, and Mojo unrolls it fully instead of running it at runtime.
@parameter
for i in range(4):
print(i)All lessons in this course
- Parametric Algorithms
- Compile-Time Loop Unrolling
- Conditional Compilation
- Constraints and Static Checks