Hello!
Just a bit of technicalities! The two types of for loops mentioned in this topic of discussion are the numeric for loops and the generic for loops.
The numeric for loop takes on the following syntax:
for var=exp1,exp2,exp3 do
something
end
While the generic for loop takes on the following syntax:
for i,v in ipairs(a) do
print(v)
end
When iterating over tables in roblox, there is no functional difference to the eventual output. However, when it comes to performance, using the numeric for loop consistently triumphs over the generic for loop. (i.e. The numeric for loop is faster.) That being said, you would only really see those effects when you are iterating over extremely large tables or performing rather complex operations over every iteration. Furthermore, there are those that “claim” that the generic for loop looks “cleaner” than the numeric for loop.
As @polill00 has mentioned, you can certainly test this out yourself in studio!
In conclusion, if you are after performance, I would recommend the numeric for loop. If you are not a stickler for that, then either form would suffice! Hope this helps!
EDIT: What I mentioned still holds true to a certain extent. HOWEVER, since last year, roblox released a new lua interpreter. Both methods of for looping are now comparable even with regards to performance, BUT the generic for loop is now slightly faster. I would relinquish the conclusion drawn previously, but just keep in mind that using either for loop would really not make that much of a difference in terms of performance!
EDIT 2: Here is a link to a devforum post in which the author performed an empirical benchmark study on the speeds of each for loop. The results are consistent with what was said above! Speed comparison : ipairs vs pairs vs numerical loop [benchmark]