Skip to content

Functions

Functions are declared using the fun keyword. They can have parameters and a return type.

The return type is specified after the parameter list, without a colon (:).

fun add(a: Int, b: Int) Int {
var result: Int = a + b;
return result;
}

If a function does not return a value, the return type can be omitted (it defaults to Void).

fun sayHello(name: String) {
// some logic here
}

Functions are called using the standard C-like syntax:

var sum: Int = add(10, 20);

Recursive function calls are fully supported.