L1kkleC
|
  |
| Joined: 11 Nov 2011 |
| Total Posts: 961 |
|
|
| 16 Nov 2014 03:54 PM |
What is i?
I see it all the time when its to do with numbers.
Like I'll see
For i = 0, 0.5, 1
Confused on that!
Also, what is this?
_, what's with that? Elaborate please. |
|
|
| Report Abuse |
|
|
Bebee2
|
  |
| Joined: 17 May 2009 |
| Total Posts: 3985 |
|
|
| 16 Nov 2014 03:58 PM |
for i = 1, 5, 2 do -- Stuff end
So, it's a loop so it repeats to code where Stuff is at.
'i' is actually a variable.
The 1 represents what 'i' will equal when the loop starts.
5 is the maximum number 'i' can be. The number can be 5, but it cannot be over 5.
The 2 is how much 'i' will be added by after each loop.
In this instance, i will equal:
1 3 5
And stops from there since 7 is > 5. |
|
|
| Report Abuse |
|
|
L1kkleC
|
  |
| Joined: 11 Nov 2011 |
| Total Posts: 961 |
|
|
| 16 Nov 2014 04:01 PM |
So I had like its own background to it. So you could say i has its own thing like while true do, true, false, end, for, if etc. |
|
|
| Report Abuse |
|
|
Xsitsu
|
  |
| Joined: 28 Jul 2009 |
| Total Posts: 2921 |
|
|
| 16 Nov 2014 04:02 PM |
"i" is just the name of a variable that is used in an iterator function. It can be named anything, but it is commonly given the name of "i" because it is only 1 character, and it is easy to remember (i is for iteration)
Whenever you use a for loop such as:
for i = 1, 10 do print(i) end
you use a variable to count your place in the loop. This variable can be given any name you want, just like all other variables can.
There's also another type of for loop.
for _, v in pairs(A_Table) do --stuff end
This is the pairs type of for loop. Instead of one variable, it uses two. The first variable "_" is the index, and the second v ariable "v" is the value. These variables can be given any name you want, but these are two very common names for them.
The for pairs loop iterates over a table, instead of just counting like the regular for loop does. the for pairs loop will go over every entry in a table and do whatever you told it to do.
"_" is usually given as the index variable name when you don't care about the index. An example would be where you just want to change the name of all the parts in a table.
for _, v in pairs(myTable) do v.Name == "NewName" end
"v" is commonly given as the standard name for the value variable, because v is short for value. The value variable is the value of what is inside of the table in the current index. The index variable is just a number, but the value variable can be various things based on what is inside of the table.
Did I answer your question or are you still confused?
|
|
|
| Report Abuse |
|
|
L1kkleC
|
  |
| Joined: 11 Nov 2011 |
| Total Posts: 961 |
|
|
| 16 Nov 2014 04:08 PM |
Your a great guy! Much clearer now. i and V are just extremely common.
Thanks! |
|
|
| Report Abuse |
|
|
|
| 16 Nov 2014 04:11 PM |
I and V stand for Index and Value, such as when you iterate through {5, 7, "Hi", workspace, BrickColor.new} Upon iterating through it, I and V become 1 - 5 2 - 7 3 - "Hi" 4 - game.Workspace 5 - BrickColor.new
K and V stand for Key and Value, such as this. {ThisKey = 5.2, AnotherKey = 17, ["Hi"] = workspace} ThisKey - 5.2 AnotherKey - 17 Hi - game.Workspace |
|
|
| Report Abuse |
|
|
L1kkleC
|
  |
| Joined: 11 Nov 2011 |
| Total Posts: 961 |
|
| |
|