Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Where does Return "return" to in these statements?

Asked by 9 years ago
if Hit.Parent.Team.Value == TeamColor then
    if Hit.Parent.Class.Value == "Unit" then
        for i,v in pairs(Selected) do
                if v == Hit.Parent then return end
            end
            table.insert(Selected,Hit.Parent)
        end

Could somebody explain where return "returns" to in these statements? If v == Hit.Parentthen will still insert Hit.Parentinto Selected? Or does it "return" to the last end? Thanks!

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

return is used in a function to stop everything. Every loop will stop. Nothing after return will be read.

You can also use return to cause a function to stop, and then give you a value. But this isn't what's happening in your code - it's just stopping.

You can read more on the wiki.

Ad

Answer this question