Hello World

Mojo is a compiled language. Every program starts with fn main(). Unlike Python, Mojo compiles your code before execution — there is no interpreter overhead.

Code

fn main():
    print("Hello, World!")

Installation of Mojo using pixi for linux. Refer the script at GitHub.

There are two ways to run Mojo code:

  1. Using the mojo command-line tool: pixi run mojo filename.mojo
  2. Using the Mojo REPL (Read-Eval-Print Loop): pixi run mojo

Key Points

  • fn — declares a compiled function (strict types enforced)
  • def — declares a Python-compatible function (dynamic types allowed)
  • main() — the entry point; execution starts here
  • Indentation defines code blocks, no braces

Constraint

Write a program that prints two lines. Verify it compiles and runs without the REPL.

Why It Matters

Compiled execution means the compiler catches type errors before runtime. This is the foundation — every optimization in later sections depends on the compiler having full type information at compile time.