Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Meaning the "i" in for i, object in pairs() ?

What does mean i in:

for i, object in pairs()
end

3 answers

Testing your code can reveal more than you'd think.

local t = {"a", "b", "c"}

for i, v in pairs(t) do
	print(i)
end
--Output: 1 2 3

i is the current index of the table, while v is the value. print is life!

If you don't know what an index and a value is, read this.

i is the variable for index, basically representing the index, example.

local table = {number = 1, 5}

for index, value in pairs(table) do
	print(index,value)
end

this returns in the output

number 1

2 5

in this example number is the index and 1 is the value.

This discussion is preserved as it was. New answers, comments, and votes are closed.