lua中for循环的四种遍历方式

lua中for的四种遍历方式区别
table.maxn 取最大的整数key
#table 从1开始的顺序整数最大值,如1,2,3,6 #table == 3
 
key,value
pairs 取每一个键值对
ipairs 取从key==1开始的顺序整数最大值,每个键值对
 
参考http://rangercyh.blog.51cto.com/1444712/1032925
不过有一个问题,
  1. tbtest = {  
  2. [1] = 1,  
  3. [2] = 2,  
  4. [4] = 4,  
  5. }  
  6. print(#(tbtest)) 
 
 
我的结果是4,按照博客理应为2才对,需要注意此处
原文地址:https://www.cnblogs.com/qooweds/p/4143474.html