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

please explain the concept "for _,v in pairs() do"?

Asked by 4 years ago

I have been looking on the wiki, but I haven't found anything. can someone explain the concept to me?

2 answers

Log in to vote
0
Answered by 4 years ago

first u need to know that the only things u can and must put in the brackets("()") in the for _, v in pairs() < must be a list, and that the "_" is a number value

great. Now what this function does is cycle once through every value in the list, starting from the first to the last value, every time it moves on from one value to another within the list, "_" will increase by 1, starting from 0 at the start of the function(before it starts cycling). The "v" will also temporarily define the current value the function has cycled to, and will be changed to the next value when the function moves on to the next value in the list. Im basically saying u can use "v" to edit the current value. Hopefully this is simple enough

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Namaste it is i, dual

The _ acts as a "throwaway" and basically useless variable to symbolise to whoever is reading the code that it is a mere placeholder variable, and not used anywhere else or further down the code. It is not treated by the compiler any different - i.e. no space is saved or speed is gained by using it, but it is good coding practise.

That is all

Answer this question