return statement is used to exit from the function. Code execution continues from where the function was called.
It can also be used to skip execution of the remaining function code.
return statement must be followed by the value if Function should return value.
Return Value
//DECLARE FUNCTION.
func test() -> String {
return("Hello from test.") //Return string.
print("Never executed") //Skipped.
}
//CALL FUNCTION.
var result = test() //Store function return value into variable result.
print(result)