Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
ZeroBits 142
10 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.

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 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 — 10y
1
What is your problem? Maybe I could provide some insight BlueTaslem 18071 — 10y
0
I fixed it. ZeroBits 142 — 10y
Ad

Answer this question