I was in a youtube video and i saw this
for _, thing in pairs (things) do
what does _, means??
I was in a youtube video and i saw this
for _, thing in pairs (things) do
what does _, means??
for loops loop through a table
for i, v in pairs(tbl) do
end
this loop goes through the table and runs the code with each index and value, the _ is put there because they don’t need the index
the index and value can be thought of as variables.
for index, value in pairs(tbl) do
--index is the index of the current pair and value is the value of the current pair
end
ok so, there are two things being set up with in for _, thing
.
The _
is basically just an index/number to signify the position of the value. Since a table is basically ordered from the first thing in the table to the last. Thing
is just a reference to well… the thing.
For an example, there are 3 models in a folder. When you turn it into a table it goes like this
The _ , thing is going to be “1, Model1” for example. The 1 being the position and Model1 being the Thing.
So if you want to access a certain amount things within a set number of Things, you use _
to do that kind of thing
Basicly what @PostVivic said. I normally use for i, v in pairs but some people will just write it in whatver way they want.
To add to this, developers tend to define the loop iterator with the _
symbol when they’re not planning to use it.