0Pricing
Mojo Academy · Lesson

Conditional Compilation

Branch code paths at compile time.

Choosing Code at Compile Time

Conditional compilation picks which code path to build based on compile-time values, so the unused branch never reaches the final program. ⚙️

The @parameter if Statement

Add @parameter to an if whose condition is known at compile time, and Mojo keeps only the branch that matches.

@parameter
if width == 1:
    scalar_path()
else:
    vector_path()

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