Skip to content

Latest commit

 

History

History
37 lines (31 loc) · 666 Bytes

File metadata and controls

37 lines (31 loc) · 666 Bytes

Function

A function is defined by the func keyword, followed by the function name, parameters in parentheses, and the return type after an arrow ->.

func myFunction(params...) -> Type {
    return ...;
}

A function can be called anywhere in the code and can be used within an expression.

myFunction(argument values...);

Example

func fibonacci(n: Integer) -> Integer {
    var a = 0;
    var b = 1;
    var i = 0;
    var temp = 0;
    while (i < n) {
        temp = a + b;
        a = b;
        b = temp;
        i = i + 1;
    }
    return a;
}
var r = fibonacci(10);
print("Fibonacci: " + r);