Originally Posted by merlight
With the minor difference that ipairs doesn't even need to get #table. The generator it returns simply stops at the first nil element.
|
Yep. My addon relies HEAVILY on tables, and tables within tables ad nauseum, and I think there's only a single ipairs() call in 800 or so lines of code. Could be wrong, maybe two. If your table contains, or may contain, or may contain sometime in the future, anything other than a pure sequential index that starts with 1, just use pairs() to cycle through the whole thing. Besides, you can do so much more with pairs() than ipairs().
Also, my new favorite ZO function is NonContiguousCount(table). I haven't seen it mentioned much, but it's basically #table for non-sequential or alphabetical tables, which is a gods-send for me.