随笔分类 -  lua

摘要:1 --逻辑表达式 2 3 --1+2+3+...+n 4 function fun1(n) 5 local sum = 0 6 for i=1,n do 7 sum = sum + i 8 end 9 return sum 10... 阅读全文
posted @ 2014-06-18 20:02 Please Call me 小强 阅读(662) 评论(0) 推荐(0) 编辑
摘要:1 -- lua链表的实现 2 3 node = {} 4 list = node 5 6 --初始化,构建一个空表 7 function init() 8 list.data = 0 --我将头结点的数据域存放链表的长度,以免浪费空间 9 list.next = nil 10 end 11 12 --向链表的尾部添加数据 13 function addRear(d) 14 node.next={}--建立一个节点,相当于malloc一个节点 15 node = node.next 16 node.next = nil 17 ... 阅读全文
posted @ 2014-03-01 16:41 Please Call me 小强 阅读(3598) 评论(0) 推荐(0) 编辑
摘要:在c语言中我三目运算符这么写: a?b:c例如:max = a>b?a:b;在lua中我们这么写max = a>b anda or b运行如下: 阅读全文
posted @ 2014-02-26 16:48 Please Call me 小强 阅读(732) 评论(0) 推荐(0) 编辑
摘要:and是与运算,返回值如下 如果前者为false或者nil,则返回前者,否则后者A and B类似如下语句if not A thenreturn Aelsereturn Bend总结:and运算只要前者不为false或者nil ,均返回后者运行截图:-------------------------------------------------------or是或运算,返回值如下: 如果前者为真返回前者,否则返回后者A or B相当于以下代码if A thenreturn Aelsereturn Bend总结:or运算,只要前者不是false或者nil,就返回前者。否则返回后者运行截图... 阅读全文
posted @ 2014-02-26 16:20 Please Call me 小强 阅读(553) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示