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
- Parametric Algorithms
- Compile-Time Loop Unrolling
- Conditional Compilation
- Constraints and Static Checks