July 2018
Beginner
202 pages
5h 42m
English
Functions don't just take input, they can also return some output to the calling code. This is done through a return value. When a function returns a value, it can be called as part of an expression or as a standalone statement.
If a function is called as a part of an expression, its return value can be assigned to a variable, or used wherever a variable could be used. The following code demonstrates this concept:
-- declare the functionfunction AddTwo(x) result = x + 2 print (x .. " + 2 = " .. result) return resultendAddTwo(3) -- calls as statementnine = 7 + AddTwo(5) -- Call as expressionprint ("adding two " .. AddTwo(3)) -- Call as expression
When a function hits a return statement, it returns whatever data follows and ...