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

What is the purpose of the # in some for loops?

Asked by 6 years ago

I'm not quite sure what this does, and I think it has something to do with a table. I just want to know the purpose of this. For example, I want to know what #list does in a portion of a follow script that some NPCS use.

local list = workspace:GetChildren()

for i = 1,#list do
--code or whatever
end
1
the # is for how long the list is... for example, suppose you have 5 items in a list, then for i=1,#list <-- # is "5" in this case because you have 5 items. Then you can use for i=1,5 to do whatever with it greatneil80 2647 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

List is a table, and #list is going to do the "--code or whatever" once for however many values are in the table. The # is just finding how "long" the table is.

Ad
Log in to vote
1
Answered by 6 years ago

works with strings and tables,

with a string, it will return the length of the string as an integer, representing how many characters are in the string

for tables, it will return the highest number index it can possibly return without getting nil,note that it will not work with string indexes

0
lol what User#24403 69 — 6y

Answer this question