What is the purpose of "for i = 1, 100 in pairs() do"?

Right. My bad. He gets the idea anyway. :+1:

2 Likes

It’s not fair on him, you’re spreading misinformation which is against devforum rules. If you seek redemption then the honourable action would be to rectify your original sin

1 Like

This one basically is doing something 100 times:

for i = 1, 100 do -- change the 100 with however amount you want to do.
 -- Do whatever here 100 times. You can also use i as how many times it ran as referenced in print(i)
end

and this one is for looping through multiple things inside of a table.

for ValueName, Value in pairs(Table) do
   -- Do whatever with the stuff in a table.
end
1 Like

That’s misinformation, because it’s actually not. Everyone makes mistakes and it’s not the end of the world to use pairs instead of ipairs. In vanilla Lua 5.1, it’s actually better to use pairs.

1 Like

Please do not go off topic “vanilla lua” rLua is quite clearly to an even an infants mind not vanilla lua

you two are getting off topic now

1 Like

I’m getting it now, thanks for those who helped me. I now much understand it.

This is a numeric loop.

i is generally iterator, but it can be anything you want as it is a variable.

for i = 1,100, 2 do
      wait()
      print(i)
end

here, 1 is the starting value. The loop will begin from 1. 100 is where the loop will stop and 2 is the increment of the loop.

if you want to go the other way round, make the increment a negative number, like -2

1 Like