现在的位置: 首页 > 综合 > 正文

泛型lua的for循环以及lua的特殊的dowhile循环

2017年12月11日 ⁄ 综合 ⁄ 共 391字 ⁄ 字号 评论关闭

范型for循环:
-- print all values of array 'a'

a={1,2,3,4,5,6,7};
for i,v in ipairs(a) do print(v) end
范型for遍历迭代子函数返回的每一个值。
再看一个遍历表key的例子:
-- print all keys of table 't'

map = {["gaoke"]=1,["gaoxin"]=2,["maqiang"]=3}
for k in pairs(map) do
 print (k);
 print (map[k]);
end范型for和数值for有两点相同:
1. 控制变量是局部变量
2. 不要修改控制变量的值

-----------------------------------------------------------------

lua的dowhile循环和C语言的又有区别:

repeat
statements;
until conditions;

抱歉!评论已关闭.