Lua for cyclically traverses several table differences: luatable
It is well known that there are two types: ipairs and pairs. I believe you are familiar with these two types. ipairs traverses them sequentially from the beginning (idx = 1, in the case of nil, the loop is exited; in the case of pairs, the loop is non-sequential traversal, as long as there are values in it, it can be traversed.
So what if I need to traverse in sequence and even if there is nil in the middle, it can be completely traversed to the end?
Next let's talk about this: Use maxSize = table. maxn (pTable) to get the location of the last element of the table (or the maximum length, including nil), and then:
For idx = 1, maxSize do if pTable [idx] ~ = Nil then -- perform corresponding processing... endend
In this way, both sequential traversal and full traversal can be achieved.