#Diffrence between for loops

1 messages · Page 1 of 1 (latest)

next crescent
#

Can someone explain to me whats the diffrence between

local array = {}

for i, v in ipairs(array) do
end

for i, v in pairs(array) do
end

for i, v in array do
end
buoyant linden
#

here it is:
the first iteration (ipairs) assumes the indices to be numbers, guarantees that you iterate in order. does not work on dictionaries.

the second iteration does not make assumptions and just iterates. the order in which iteration occurs is NOT guaranteed.

the third iteration is a consolidation of the previous two.
if the table is an array [ordered number indices] then it acts like ipairs.
else, it acts like pairs.

loud havenBOT
#

studio** You are now Level 2! **studio

next crescent
#

so i just dont use ipairs or pairs at all

#

or?

buoyant linden
#

realistically, you don't need to use those anymore, no.

next crescent
#

alr alr

#

thanks

maiden cypress