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

which is better to use here, pairs or ipairs() ??

local VotingUIs = {
	script.Parent:WaitForChild("Classic"),
	script.Parent:WaitForChild("Combat"),
	script.Parent:WaitForChild("Double Killers")
}
for i, v in ipairs(VotingUIs) do
	print(v)
end

using both pairs and ipairs work here, but i want to know which is better to use in this situation.

even though the forum says that ipairs() is for arrays, pairs() seem to work for arrays as well

1 comment

1

they would be the same for that i think. pretty sure ipairs and pairs are the same but ipairs stops when something is nil https://scriptinghelpers.org/questions/2725/difference-between-pairs-ipairs-and-next

1 answer

✓ Accepted answer

Truthfully, it boils down to personal choice here. Both in pairs and in ipairs will work for an array, but only in pairs works for dictionaries.

If you want something faster you could use a for i = 1,n loop and index the table using that like so:

local table = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }

for i = 1, #table, 1 do
	print(table[i])
end

Again, they accomplish the same thing it all boils down to aesthetic.

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