I’m making a module so that you can loop without having to use continue as thats only a luau thing. Right now the module works like so:
Loop:Loop(1, 10, 1, function(index, kill)
if index == 5 then return end
if index == 7 then kill() return end
print(index)
end)
Loop:Loop({"apple", "banan", "orange"}, function(index, value, kill)
if index == 2 then
kill()
return
end
print(index, value)
end)
As you can see right now for the loop to end after you use kill you need to call return which is annoying to do. To continue the loop just use return and using kill will stop the function from running. Here is the module code:
local arguments = {...}
local _break = false
if typeof(arguments[1]) == "number" then
for index = arguments[1], arguments[2], arguments[3] do
if _break then break end
arguments[4](index, function()
_break = true
end)
end
elseif typeof(arguments[1]) == "table" then
for key, value in next, arguments[1] do
if _break then break end
arguments[2](key, value, function()
_break = true
end)
end
end
All this dose is call the function and pass in the values such as index, key, value etc… It also passes in the kill function and when called it sets _break to true so that next loop will break. However this will not kill the function so I also need to call return afterwards. I have already tried using threads and killing the thread once _continue is set to true however I was trying to task.cancel() the thread and it was nil. If you know how to do this please lmk!