In this tutorial you will learn about the Swift Return Statement and its application with practical example.
Swift Return Statement
In Swift, the return statement is simply used to return values or expression from enclosing function. The return statement allows you to return single or multiple values in single statement.
Syntax:-
1 |
return <value> |
Or
1 |
return <expression> |
Example:-
1 2 3 4 5 |
func sum( n1:Int, n2:Int) -> Int { return n1 + n2 } print("W3Adda - Swift return statement") print(sum(n1: 3, n2: 2)) // |
Here, return statement return the sum of two number passed in the enclosing function named sum.
When we run the above swift program, we will see the following output –
Output:-