Sunday, May 13, 2012

Looping

 local a = {Mustaine = "Megadeth", Hetfield = "Metallica", King = "Slayer", Yngwie = "Rising Force"}  
   
 print ("--next--------------------------------------")  
 do   
      local k, v  
      k, v = next(a, nil)  
      while k do  
           print(k, v)  
           k, v = next(a, k)  
      end  
 end  
 print ("--pairs--------------------------------------")  
 do  
      for i, v in pairs(a) do  
           print(i, v)  
      end  
 end  

No comments:

Post a Comment