I'm very confused on what the difference is between for _,v
and for i,v
. Here is an example of those 2 for
statements being used;
for _,v
local Names = {"Player1","Player2","Guest1000"} for _,names in pairs(Names) do --blah blah blah codes idk end
for i,v
local Names = {"Player1","Player2","Guest1000"} for i,names in pairs(Names) do --blah blah code idk xd end
Any help?
What's the difference between for _,v and for i,v? Actually, there's no major difference. When you use a _ (underscore) you're actually just removing the index (or i as most people define it). The variable(s) within a for loop can be defined as anything.
Examples For example, I could do:
local myTestTable = {"Hello World!"}; for index, value in pairs(myTestTable) do print(index, value); end
That's equivalent to doing:
local myTestTable = {"Hello World!"}; for i,v in pairs(myTestTable) do print(index, value); end
Conclusion Basically name the variables in your loops the way you'd like to name them. Back to ,v if you know you're not going to use the index (i) then some developers will just put an underscore (). When they put that underscore they know they won't be using the index and it's used to prevent the defining of another variable.
I hope I answered any questions or concerns you may have had :)
Some people like using for _,v instead of for i,v because they like eliminating the index value as a reminder that they're not going to use it in their code. It's just a style to.
I might be wrong, I don't know either o-o