So basically I have cam Across these two methods and said... "Hey could these two methods of looping be alike" but now I want someone to actually tell me if
For i,v in pairs(object:GetChildren()) do and for i = 1, #OfChildren do are alike.
So basically I have cam Across these two methods and said... "Hey could these two methods of looping be alike" but now I want someone to actually tell me if
For i,v in pairs(object:GetChildren()) do and for i = 1, #OfChildren do are alike.
The for i,v in pairs() do function gets everything in a table or item. v is everything inside that array or item. i is the number of each item. So suppose that you wanted to print all of the items. So you would do print(tostring(v)). Or let's say warn(tostring(v)). Same thing with i.
The for i = 1, 10 do function stores the variable i as a starting value (left) and an ending value (right). 1 is our starting value, while 10 is our ending value. Like in your for loop, you can do for i = 1, #EndingValue do. This can be used to move parts, or even rotating parts.
Hope this is helpful. If you need more help, visit the developer wiki on both types of for loops.
Also you can use it for fading GUIs out.
This discussion is preserved as it was. New answers, comments, and votes are closed.
4 comments
The left is a generic loop which uses an iterator. The right is a numeric loop which is the fastest way to loop through an array.
hmmmm.
There are different types of iterators. https://www.lua.org/pil/7.1.html https://www.lua.org/pil/7.3.html
I am not sure what else to say you are comparing two things which have no direct relation.