Velo by Example: Functions

Functions are first-class citizens in Velo. The last expression in a function body is automatically the return value.

A function is declared with func, parameter types, and a return type. The last expression becomes the return value — no return keyword needed.

func add(int a, int b) int {
    a + b;
};

int result = add(5, 3);  # 8

Functions without parameters use empty parentheses.

func getAnswer() int {
    42;
};

int answer = getAnswer();

Functions that don't return a value use the void return type.

func printHello() void {
    term.println("Hello");
};