✓ Accepted answer
Formally, the definition of the return keyword is "a statement that tells the program to leave the subroutine and return to the return address". Essentially, if we wish to return a result from a computation or various other scenarios that is concluded from a function, we use this keyword to define what we wish to give. See this example of it's potential applications:
local numberA = 5
local numberB = 2
local function multiplyNumbers(a,b)
return a * b
end
local result = multiplyNumbers(numberA, numberB)
This will return the multiplication of parameters A and B to wherever this function—or the fancy term "subroutine"—was called, as aforementioned above. To break this down, this is what's occuring:
local result = a * b
local result = 10
An easy way to grasp return, is to see is as the "give back" keyword. Before I finish, let's see another example:
local hello, world = "Hello", "world!"
local function concatenateStrings(a,b)
return tostring(a..' '..b)
end
print(concatenateStrings(hello, world))
2 comments
Thank you so much I get what you mean but what is sub routine?
A subroutine is the formal definition of a "function".