Is there a quick way to stop a “for _,v in pairs(list) do” loop without also ending any other loops/functions that the loop is in?
lets say you are trying to change one red rock to blue in a list of rocks. In this list there are several red rocks.
for _,rock in pairs(rocks) do
if v.BrickColor == "Bright red" then
rock.Color = Color3.new(0,0,1)
-- break? What just ends the loop without also ending the function that the loop is in?
end
end
-- rest of script
I figure I’m either misunderstanding one of these commands or there’s a command I don’t know about to do this right? Does break just end the loop or function you use it in or does it translate to it’s parent loops/functions?
break is your friend in this case.
Break is a control statement in Lua that transfers the control over to the first statement outside the loop.
Example:
for i = 1, 5 do
if i == 2 then
break
end
print(i)
end
print("post-loop")