miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Sep 2011 02:10 PM |
1) What does i,v mean when you say generic loops?
2) What's the difference between pairs and ipairs? |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
| |
|
|
| 03 Sep 2011 02:15 PM |
| They're the things returned by the iterator (which is the 'next' function). ipairs ignores non-numeric indices, pairs doesn't. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Sep 2011 02:17 PM |
-_-
I'm gonna learn generic loops soon, so that doesnt make sense to me one bit.Is there some kind of example or can you explain it a different way? |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2011 02:19 PM |
| In short, when using pairs or ipairs, i is the index, v is the value. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Sep 2011 02:20 PM |
| Can you give me a simple example? |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2011 02:26 PM |
MyTable = {"I", "like", "WiseBot"} for i, v in pairs(MyTable) do print(i,v) end
1 I 2 like 3 WiseBot |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Sep 2011 02:32 PM |
| Ok, what in that print waht does i and v mean?And if you used ipairs would it still work? |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2011 02:32 PM |
| I told you, i is the index, v is the value. And yes, it would work with ipairs. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Sep 2011 02:37 PM |
Ok, whats better to say?ipairs or pairs or does it not matter?
Also, so your saying that like v is Mytable and i is I, Like, robot? |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2011 02:38 PM |
| Use pairs, unless you want to only iterate through numeric indexes. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Sep 2011 02:39 PM |
| Ok andwas I right about the v and i? |
|
|
| Report Abuse |
|
|