|
| 29 Sep 2012 10:15 PM |
Whats the real dfference between them?
I always used the for i = do with tables and stuff... Like :GetChildren()
But I never knew what pairs and ipairs are and why they're better...
I just figured theyre better cause all the pro scripters use them over for i = do :\ |
|
|
| Report Abuse |
|
AIAdvance
|
  |
| Joined: 28 Sep 2012 |
| Total Posts: 18 |
|
|
| 29 Sep 2012 10:21 PM |
Differences
Table = {"Win",nil,"Black"}
for n=1,#Table,1 do print(Table[n]) end > Win nil Black
for n,o in pairs(Table)do print(n,o) -- n is the same n as the first for loop, o is the value end > 1 Win 2 nil 3 Black
for n,o in ipairs(Table)do print(n,o) end > 1 Win
Why didn't the last one print 2 nil 3 Black? Because ipairs stops when it reaches the first nil value, where as pairs runs through the whole table. |
|
|
| Report Abuse |
|
|
| 29 Sep 2012 11:29 PM |
| k thx :P Good luck on your AI :D |
|
|
| Report Abuse |
|