generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Looping through a table!

Previous Thread :: Next Thread 
Clxver is not online. 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
FactualTheory is not online. FactualTheory
Joined: 10 Sep 2013
Total Posts: 1365
24 Jul 2015 09:45 PM
TABLES

are not designed for loops

I hate them not looking at this thread anymore
Report Abuse
Clxver is not online. 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
GeoVolcano is not online. GeoVolcano
Joined: 05 Jul 2012
Total Posts: 1433
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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image