I know 2 types of For Loops:
for i = n,n,n --The one with three numbers -- (Insert code here) end
for i = n,n -- The one that increments by one -- (Insert code here) end
--But, I don't know what this is:
for i = 1, #variables -- #idk_what_this_is -- (Insert code here) end
Can someone explain to me the third type of for loop that I see in some scripts?
its the same as the second one, normally people use this if they want to loop through a table
the # means the amount of indexes in a table
local table = {a,b,c} for i =1,#table do print(i) end -- is the same as for i = 1,3 do print(i) end
but people use for i =1,#table because sometimes they dont know how long a table is
Aazkao almost nailed it on the head. It is just like the second one, however the 3rd number represents the step. You can read more about it in our glossary. The step
is the increment it will count to get from one number to the next. It can be negative, but the 2nd number would have to be lower than the first.