范型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
statement......
阅读全文