I have this line of code here:
if place_holder then return end
I just want some quick clarifications on the “Return End” part:
Does it mean “return nothing, then end” or does it mean “return the keyword “end” to the script”?
Thanks!
I have this line of code here:
if place_holder then return end
I just want some quick clarifications on the “Return End” part:
Does it mean “return nothing, then end” or does it mean “return the keyword “end” to the script”?
Thanks!
A return statement returns occasional results from a function or simply finishes a function.
There is an implicit return at the end of any function, so you do not need to use one if your function ends naturally, without returning any value.
In that code, you aren’t returning anything. It’s just a way to write it in one line, it’s the same as doing:
if palce_holder then
return
end
Hi! Can you describe what you mean by a function ending naturally? Please see another piece of code:
function test (noLol)
if noLol then return end
else --do something
end
would there be any difference if I just did: then end
instead of then return end
because I’m not passing anything to anywhere?
Your sample code won’t work in this case. To expand that code visually, it would look like this:
function test (noLol)
if noLol then
return
end
else -- do something (This would error as else is not
-- supported with any if conditions)
end
A better example to explain “if place_holder then return end” would be this:
local function RunIfHave5Apple(apples)
if apples < 5 then return end -- stop the code from continuing to run
print("I have 5 apples :)") -- code would run here if apple is greater or equal to 5
end
In your case, if the statement is true it will just stop the execution, which means it won’t run anything below.
If you do this in a function, it will simply exit out of the function and continue with anything outside of the function.
sorry! I meant to put the “else” before the “end” like your example about the apples. @Xacima just answered what I was looking for, but thank you for pointing that out!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.