Functions can return a result using the return
keyword:
func add(a, b):
return a + b
var result = add(2, 3) # result is 5
You can also define the type of the returned value by appending -> ReturnType
to the function declaration, it will spit out an error if you try to return something that isn't the correct type.
# Returns integer
func add(a: int, b: int) -> int:
return a + b
# This won't work
func add(a, b) -> int:
return "Hello"
Comments