How to stop part of a pair loop

  1. What do you want to achieve?
    I want to be able to stop a pair loop, but continue the rest of the loop without ending a whole function.

  2. What is the issue?
    I don’t know what to use, I will not use break cause that stops the whole loop and return ends the function that runs the loop entirely.

  3. What solutions have you tried so far? Like before I have tried break and return and also did a google search but found nothing that could help.

1 Like

break or continue

for _, v in ipairs(things) do
    if isCool(v) then 
        break
    end 
end

break
continue

1 Like

If you can’t use break or continue because you don’t actually want to do that to the loop where you want to do it, you need to use a variable in the outer loop to keep track of whether or not the outer loop should break or continue, and then set it in the inner loop.

1 Like

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