lua -- next
来源:互联网 发布:sentinel 2数据 envi 编辑:程序博客网 时间:2024/06/05 10:51
next 允许程序遍历表中的每一个字段,返回下一索引和该索引的值。
local a = {a = "a", b = "b", c = "c", d = "d"}local valuewhile next(a, value) do print(next(a, value)) value = next(a, value)end
输出如下:
next函数原型是next(table[,index])
table:要遍历的表
index:next返回的值即是index索引的下一个值,当index为nil时,将返回第一个索引的值,当索引号为最后一个索引或表为空时将返回nil
注意:next(table)可以判定表table是否为空
所以判定表是否为空的方法有:
1、#table,当table为数组是直接返回table表长度
2、当table是字典时,返回table的长度
function table.size(t) local s = 0; for k,v in pairs(t) do if v ~= nil then s = s+1 end end return s;end
3、next(table)
阅读全文
0 0
- lua -- next
- Lua之Next用法
- lua next用法
- lua next 用法
- lua next 用法 table 空的判断
- lua next 用法 table 空的判断
- lua next 用法 table 空的判断
- Lua语法小贴士(十六)pairs和next
- LUA PANIC: unprotected error in call to Lua API (invalid key to 'next')问题
- next()
- next()
- Next
- next()
- next
- permutation_next..._next_permutation, next, next, next...
- LUA
- Lua
- LUA
- 2017 ACMICPC Asia Regional Shenyang Online 个人题解汇总
- Android设置“android:clickable="false"无效。点击事件依旧触发
- 每天一python 题 0005
- Linux 文件操作之文件管理(一)
- Opencv入门(显示图像)
- lua -- next
- 深入理解javascript原型和闭包(17)——补充:上下文环境和作用域的关系
- ECharts3 实现四象限图
- 随机数测试函数 (rand() 和srand() )
- 密码编码学初探——数论和有限域
- Android图表库MPAndroidChart(六)饼状图 -折线百分比
- Flie
- 用 eclipse ndk 编译 cocos2d-x for Android
- My First bo ke!