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!

6 comments

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.

0

(may not be the best explanation, so just know this isn't the exact 'what its about')

0

oh

0

Ill try that

0

just for testing

0

Thanks for giving me a general idea