Anyone Can Explain Me The Return Thing?

Hi I'm learning swift but I didn't understand the Return keyword which is used in the functions. Is there anybody who can explain me that ?

Answered by Documentation Engineer in 613896022
There are two kinds of functions — functions that you call because they do something, and functions that you call because they give you back some value. That second kind of function uses return to mark the value it sends back. For example, here's a function that takes a number and gives you back twice that value:

Code Block swift
func twice(_ number: Int) -> Int {
return number * 2
}
let x = twice(7)
print("Twice 7:")
print(x)



For more information, check out the Functions chapter of "The Swift Programming Language".
Accepted Answer
There are two kinds of functions — functions that you call because they do something, and functions that you call because they give you back some value. That second kind of function uses return to mark the value it sends back. For example, here's a function that takes a number and gives you back twice that value:

Code Block swift
func twice(_ number: Int) -> Int {
return number * 2
}
let x = twice(7)
print("Twice 7:")
print(x)



For more information, check out the Functions chapter of "The Swift Programming Language".
Thanks man, you really helped me!

Anyone Can Explain Me The Return Thing?
 
 
Q