How to exit out of a function more deeply nested into another function or loop

how would you exit from a function more deeply nested withen functions and loops?
for example:

local function a()
  for i=1, 5 do
    local function b()
      -- how would you exit out of all these because using return would only exit out of function B

thanks a lot!

Why have a function inside of a loop?

Anyway, you could probably use break.

is there not a one event where you could just straight up exit from all of these, because this my code is very long and ill have to put return or break and the end of all loops and functions.

For context: Why do you have a function nested in a loop? I might need some more code to assist further.

You could control it all with a Boolean.

oh its because I have a function that sets a button and then a loop, at the end of the loop I have another button appear and there is a function to check when it is clicked, and then it loops through a folder and creates a new instance.

You could use return in function b and then use break after function b.

I still don’t really get why you have a function in a loop, can you explain further? Sorry…

so I have a function that activates when a button is pressed, then theres a loop that makes an animation repeat a couple of time and then after the animation another function appears that creates a new instance when a button is pressed