Answered by
5 years ago Edited 5 years ago
pairs
will iterate through every value in a table that isn't nil
(the indices here don't matter, i just chose them randomly)
09 | for i, v in pairs (tbl) do |
if you run that code using pairs, this will be the output (or at least all of these values will be in the output)
as you can see, it went through every value in the table, except for stupid
, since it was nil
on the other hand, ipairs
only iterates through numeric indices, and will stop if there isn't an index for the next number
if you ran the same code, but with ipairs
instead of pairs
, this would be the output
that's because ipairs only went through the indices that were numbers, and it didn't print index 4 because the table skipped index 3