How to change for loop index

I am running a for loop that runs for the length of an array
Sometimes I need to remove stuff from the array while it is running
I use table.Remove to do this, but the problem is that the for loop index needs to go down aswell
I try this by doing i-=1 (i=i-1) but that does not work. Does anyone know how to do this?

for o=1,1000000 do
	print(o)
	if o>2 then
		print("a")
		o=o-1
	end
	wait()
end

This code is a mock up and simplified version of the actual for loop
image

Don’t use a for loop then. Use a regular while loop so you have more control over the iteration.

local o: number = 0 
while o < limit do
	o += 1
	if o > 2 then
		print("a")
		o -= 1
	end
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.