0Pricing
Mojo Academy · Lesson

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

  1. Parametric Algorithms
  2. Compile-Time Loop Unrolling
  3. Conditional Compilation
  4. Constraints and Static Checks
← Back to Mojo Academy