Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

When should we use return and how to use it?

Asked by 5 years ago

Hi, I would like to know when to use return. The only thing I know where to use return is a simple add function, like this:

function addnum(num1,num2)
    return print(num1,num2)
end

addnum(1,2)

Although the same results can be seen without return:

function addnum(num1,num2)
    print(num1 + num2)
end

addnum(1,2)

I would appreciate it if someone could tell me when to use return and how to use it.

Thanks to those who helped!

0
Return is basically, giving you back something instead of just, lets say doing it right there and then. So in the 1st code block, you can see how you used `print()`. If you didn't and just decided to put num1, num2 and decided to get the value, you'd do `print(addnum(5, 2))`. Return is useful if you're trying to get a value or bool from a function. TheePBHST 154 — 5y
0
(may not be the best explanation, so just know this isn't the exact 'what its about') TheePBHST 154 — 5y
0
oh HomieFirePGN 137 — 5y
0
Ill try that HomieFirePGN 137 — 5y
View all comments (2 more)
0
just for testing HomieFirePGN 137 — 5y
0
Thanks for giving me a general idea HomieFirePGN 137 — 5y

Answer this question