I cannot rap my head around that.
COMMUNITY QUESTION
difference between end and return?
1 answer
The end keyword ends a block, such as a function or an if statement. The return keyword, however, stops execution of a function and returns the value you provide after the keyword. If you don't provide any value, it will return nil.
function test(s)
if s == 2 then
return "hello"
elseif s == 3 then
return
elseif s == 4 then
return 50
end
return "yolo"
end
print( test(2) )
--> hello
print( test(3) )
--> nil
print( test(4) )
--> 50
print( test() )
--> "yolo"
print( test('yo dawg') )
--> "yolo"
This discussion is preserved as it was. New answers, comments, and votes are closed.
