Clxver
|
  |
| Joined: 19 Oct 2014 |
| Total Posts: 727 |
|
|
| 24 Jul 2015 09:42 PM |
When you loop through a table, would YOU use a normal for loop, or a generic for loop... and why?
(this is just a general discussion topic, that could help others (like myself) to know when to use a normal or generic for loop and when not to use one) |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2015 09:45 PM |
TABLES
are not designed for loops
I hate them not looking at this thread anymore |
|
|
| Report Abuse |
|
|
Clxver
|
  |
| Joined: 19 Oct 2014 |
| Total Posts: 727 |
|
|
| 24 Jul 2015 09:50 PM |
| Using the :GetChildren() function returns a table, does it not? Thus, we'd loop through that, right? |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2015 09:54 PM |
for a = 1, #YourTable do --stuff end
for i,v in pairs(YourTable) do --stuff end
1st one should be used if you are doing anything a set amount of times based on the table, like accessing an amount of zombies based on the length of the table
2nd one should be used if you are using it's properties to change another object or itself. |
|
|
| Report Abuse |
|
|
sparker22
|
  |
| Joined: 11 Mar 2010 |
| Total Posts: 846 |
|
|
| 24 Jul 2015 10:05 PM |
@GeoVolcano Generic for loops covers both use cases. So do numeric for loops. It really doesn't matter, but generic usually loops nicer.
Since the i variable in the generic for is equal to the a variable in the numeric for, that's covered. So you can always reference the index.
Generic for loops have the v variable which is a direct reference to the object, but you can easily just do Tab[a] in the numeric for loop to get the same result. |
|
|
| Report Abuse |
|
|