Does a for loop completely stop the function, or does it just stop one loop and another will be run?

Whenever running this for loop here, it prints “not claimed by player 1”, “tycoon 1 claimed by player 1”, “not claimed by player 2”, and then nothing else. Obviously the first tycoon is claimed so I understand why it is returning end, but I’m just not sure if the return end stops all loops or if the first loop is stopped then the second loop runs.

for _, tycoon in workspaceTycoons:GetChildren() do
		repeat task.wait(.1) until player.Character
		if player:FindFirstChild("ClaimedTycoon") then return end
		print("not claimed by "..player.Name)
		if tycoon:GetAttribute("Owner") ~= "Empty" then return end
		print(tycoon.Name.."claimed by "..player.Name)
		module.AssignTycoon(player, tycoon)
	end

return exits out of a function, so the second loop and any loops after that won’t run.

(sorry if i misunderstood the question)

3 Likes

To add to what @PolyLacticSugarcane said, if you want the loop to continue but skip the lines if the if statement is false then instead of using then return end you should write then continue end and the loop will skip the lines below without stopping the function and the loop

2 Likes

Thank you this fixed my problem.

Yes you understood my question correctly, thank you

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.