It looks like you're new here. If you want to get involved, click one of these buttons!
if i==3 then break end
--------------- --case 1 --------------- a={...} for i=1, 10 do a[i]=i end count=1 for i=1,#a do i=nil print(i,a[i],a[count]) count = count + 1 end --[[ got: ----------------------- i a[i] a[count] ----------------------- nil nil 1 nil nil 2 nil nil 3 nil nil 4 nil nil 5 nil nil 6 nil nil 7 nil nil 8 nil nil 9 nil nil 10 ----------------------- ]] --------------- --case 2 --------------- a={...} for i=1, 10 do a[i]=i end count=1 for k,v in pairs(a) do v="e" k=nil print(k,v,a[k],a[count]) count = count + 1 end --[[ got: ----------------------------- k v a[k] a[count] ----------------------------- nil e nil 1 nil e nil 2 nil e nil 3 nil e nil 4 nil e nil 5 nil e nil 6 nil e nil 7 nil e nil 8 nil e nil 9 nil e nil 10 ----------------------------- ]]
Likes: ar2rsawseen
Comments
For loops in Lua are different than C or many other language loops.
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
Likes: ar2rsawseen
[-] Liasoft
You should never change the value of the control variable: the effect of
such changes is unpredictable. If you want to end a for loop before its normal
termination, use break.