ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

【2014-08-28】Lua快速学习笔记:语句

【2014-08-28】Lua快速学习笔记:语句 [历史归档]本文原发布于 cstriker1407.info 个人博客内容为历史存档仅供参考。发布时间2014-08-28 标题Lua快速学习笔记语句分类编程 / C C / Lua 标签lua·语句Lua快速学习笔记语句备注算术操作符关系操作符逻辑操作符多重赋值语句局部变量与语句块if结构while语句repeat..until类似于do..while数字型for语句泛型for语句关于pairs 和 ipairs测试用Return语句备注1 本笔记只记录了LUA的一小部分内容对于LUA的描述并不全面以后随用随增加吧。2 本笔记参考《Lua程序设计 第二版》截图和代码属于原作者所有。3 作者初学LUA经验和能力有限笔记可能有错误还请各位路过的大牛们给予指点。算术操作符Lua没有整数和浮点数的区别因此关于取模运算符如下图关系操作符nil只与其自身相等。逻辑操作符多重赋值语句v1,v210,20;print(v1:..v1.. v2:..v2);--输出v1:10 v2:20v1,v2v2,v1;print(v1:..v1.. v2:..v2);--输出v1:20 v2:10局部变量与语句块Local v10;--显式界定一个语句块dolocalv100;print(v);--输出100endprint(v);--输出nilif结构v10;ifv110thenprint(v1 10);endifv110thenprint(v1 10);elseprint(v1 10);endifv110thenprint(v1 10);elseif(v120)thenprint(v1 20);elseprint(v1 20);endwhile语句localnum0;whilenum4doprint(num);numnum1;endrepeat…until类似于do…whilelocalnum5;repeatprint(num);numnum-1;untilnum0数字型for语句不要在循环过程中修改控制变量的值泛型for语句这里先简单的笔记下最常用的tb{A,B,C,nameHello,[10]D,[age]20};fori,vinipairs(tb)doprint(i,v);endprint();fori,vinpairs(tb)doprint(i,v);end输出1A2B3C1A2B3C10D关于pairs 和 ipairsIpairs【 http://manual.luaer.cn/pdf-ipairs.html 】Returns three values:an iteratorfunction,the table t,and0,so that the constructionfori,vinipairs(t)dobodyendwill iterate over thepairs(1,t[1]),(2,t[2]),···,up to the first integer key absent from the table.Pairs【 http://manual.luaer.cn/pdf-pairs.html 】Returns three values:the nextfunction,the table t,andnil,so that the constructionfork,vinpairs(t)dobodyendwill iterate over all key–value pairs of table t.测试用Return语句
返回列表