Functions
Basic declaration
Section titled “Basic declaration”Functions use fun. The return type comes after the parameter list:
fun add(a: Int, b: Int) Int { return a + b;}Void functions
Section titled “Void functions”If no value is returned, the return type can be omitted:
fun logName(name: String) { // ...}Calling functions
Section titled “Calling functions”var total: Int = add(10, 20);More examples
Section titled “More examples”fun distance(x: Int, y: Int) Int { return x - y;}fun main() Int { var total: Int = add(4, 5); return distance(total, 3);}For overloads, named arguments, references, and varargs, continue with the next guides.