通过lua自带例子学习lua 05

-- Example 21 -- repeat until statement.

a=0
repeat
a=a+1
print(a)
until a==5


-------- Output ------

1
2
3
4
5

-- Example 22 -- for statement.

-- Numeric iteration form.

-- Count from 1 to 4 by 1.
for a=1,4 do io.write(a) end

print()

-- Count from 1 to 6 by 3.
for a=1,6,3 do io.write(a) end


-------- Output ------

1234
14

-- Example 23 -- More for statement.

-- Sequential iteration form.

for key,value in pairs({1,2,3,4}) do print(key, value) end


-------- Output ------

1 1
2 2
3 3
4 4

-- Example 24 -- Printing tables.

-- Simple way to print tables.

a={1,2,3,4,"five","elephant", "mouse"}

for i,v in pairs(a) do print(i,v) end


-------- Output ------

1 1
2 2
3 3
4 4
5 five
6 elephant
7 mouse

-- Example 25 -- break statement.

-- break is used to exit a loop.

a=0
while true do
a=a+1
if a==10 then
break
end
end

print(a)


-------- Output ------

10

 

转载于:https://www.cnblogs.com/sdlypyzq/archive/2013/04/06/3002482.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值