Skip to content

Parameters and Return Values

Parameters allow you to pass information into functions, making them flexible and reusable. Each parameter has a name and a type. Functions can also return values using the return statement, and the return type is specified after a colon in the function signature.

You can define functions with multiple parameters, and the return value can be used in expressions or assigned to variables.

Example

fn add(a: Int, b: Int): Int {
    return a + b
}

let result = add(2, 3)
print(result)  # Should print 5

Here, add takes two integer parameters and returns their sum. The return type is Int, and the function is called with two arguments.


Next
Up