Besides that though, next can make for some interesting use cases such as checking if a table is truly empty. Consider the following:
local function isEmpty(t)
return next(t) == nil
end
But Colbert, why not #t == 0, isn’t what you’re doing redundant? The len operator only works for arrays so if you have a dictionary (including if indexed by numbers if non-contiguous) len will return 0 but it’s not actually empty. Rare case you’ll need it but it may come up some time.
For generic for iteration there’s generally no case where you need or want next because it’s not clear what you’re iterating over to either yourself or fellow developers and you want to stay consistent when using offered generic iterators. ipairs for arrays, pairs for dictionaries and a custom iterator if you have that one esoteric case where neither ipairs or pairs work (i.e. for priority, name, handler in handlers:GetIterator() do).
Correct me if I am wrong, but there is no difference between pairs() and next(),
but I prefer to use the latter (I think it makes the code look more organized) and I don’t know why lol.