Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a way to halt a for-loop without breaking?

I can't find a function for this on the wiki, I need it for a user-input system on my WIP hacking game.

1 answer

✓ Accepted answer

break is the way to break a loop. return also works (but obviously has extra functionality of completely exiting a function block instead of just a loop and giving a [set of] value[s]).

The only other way to prevent a loop from continuing is to cause its condition to be false, but in the context of a for loop that is essentially impossible.

I suppose a third way to stop it would be an error. Those break execution all the way up to the next protected call (pcall, ypcall, xpcall), which is obviously a horrible way to manage your code but maybe something interesting could come of it.

3 comments

0

Thanks for the answer, I just thought of a horridly ugly way to fix my problem. it won't be pretty, but it might work.

1

What is your problem? Maybe I could provide some insight

0

I fixed it.

This discussion is preserved as it was. New answers, comments, and votes are closed.