0

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

ZeroBits 142
7 years ago

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

2
BlueTaslem 18054
7 years ago

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.

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. ZeroBits 142 — 7y
1
What is your problem? Maybe I could provide some insight BlueTaslem 18054 — 7y
0
I fixed it. ZeroBits 142 — 7y