Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What's the difference between a numeric for loop and a generic for loop? [closed]

Asked by 11 years ago

Could you please explain the difference between a numeric and a generic for loop?

0
You can see the [LuaLearner's lesson](http://lessons.lualearners.org/lesson?id=86) on those loops. Shawnyg 4330 — 11y
0
Spyspace12, please leave a comment or append an edit to the end of your post. Do not remove your post or add an answer. If you want to say "Thanks", simply click the Accept Answer button. User#11893 186 — 11y
0
kk spyspace12 -7 — 11y

Locked by FunctionalMetatable and Leamir

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
3
Answered by
jobro13 980 Moderation Voter
11 years ago

Basically, a numeric for loop loops over a certain array of numbers with a certain increment. For example, for x = 1,5,2 do print(x) end will print 1, 3 and 5.

A generic for loop is another type of for loop. You basically use the for loop as iterator again, but now you will use a function to get the values. One of the most used functions for a generic for loop is pairs(). This will slide a table index and it's value to the values;

local tab = game.Workspace:GetChildren()
for index, instance in pairs(tab) do
print("Instance number: "..index.." of game.Workspace has name: ".. instance.Name)
end

This will print all names of all children of workspace.

Ad