JoshRBX
|
  |
| Joined: 19 May 2012 |
| Total Posts: 8778 |
|
|
| 16 Oct 2016 11:03 AM |
I never really thought about learning the different "methods" of for loops, but I thought that I might as well ask seeing as everyone else in this community knows when and where to use them.
If I was to write a for loop, I would write something like...
for i=1,#workspace:GetChildren() print(workspace:GetChildren().Name) end
Although, I'm always seeing things like "ipairs" and "next".
Could someone please explain to me what these mean and how to use them?
Thanks a lot!
|
|
|
| Report Abuse |
|
|
JoshRBX
|
  |
| Joined: 19 May 2012 |
| Total Posts: 8778 |
|
|
| 16 Oct 2016 11:05 AM |
I really messed up the code.
for i=1,#workspace:GetChildren() do print(workspace:GetChildren()[i].Name) end
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 16 Oct 2016 11:08 AM |
generic for loops and such:
for i = 1,#thing do print(thing[i].Name) end
for i = 10,0,-1 do print(i) end
for i,v in next, thing do print(v.Nae) end
for i,v in pairs(thing) do print(v.Name) end
for i,v in ipairs(thing) do print(v) end
|
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 16 Oct 2016 11:26 AM |
www . lua . org / manual / 5.1 / manual . html # 2.4.5
|
|
|
| Report Abuse |
|
|