How to restart a while loop

I was wondering how to restart a while loop if a condition is met once again.

For example, a condition is met at the beginning but then is changed and the loop stops, and then the condition is met once more and it does not restart.

I’ve tried solutions from other topics that have a similar issue but none of them seemed to work.

1 Like

I don’t think its possible honestly.

Oh, okay. I’ll try something else.

actually maybe you can put it in a function and have an coroutine continually checking the condition and if its true or something you call the function.

local a=0
function myfunc ()
 while a<100 do
  a=a+1
 print("loop is running")
 end 
end
myfunc()
a=0
myfunc()
1 Like

You can restart a while loop only if you can start it with a function.

local function startLoop()
	while something do
		-- super random ninja horse code
	end
end

startLoop() -- just call this
local i = 0
while wait() do
i += 1
if i % 2 == 0 then
continue -- It works like break, but instead of breaking, the script will go to the fist loop's command and skip the remaining code of the loop
end
print(i)
end
2 Likes