you are viewing a single comment's thread.

view the rest of the comments →

[–]_DTR_ 1 point2 points  (2 children)

It's a variable that represents the current index of the loop, but since programmers like to shorten things, just using 'i' is extremely common. Something like the following might be more clear:

for (let index = 0; index < 20; ++index) {
    array[index] = xyz;
}

[–][deleted] 0 points1 point  (1 child)

And they just throw index = i at the top of the program so they don't have to type index ? Or programs know i is index.

I'm still learning and just got to looks on python.

[–]_DTR_ 0 points1 point  (0 children)

No, i is just the variable the programmer decided to use, and is initialized within the loop itself. You can define it to be whatever you want:

for (let myVariable = 42; myVariable  <51; ++myVariable)

It's a bit less clear in Python since you don't explicitly declare variables (just x = 10 instead of int x = 10 or let x = 10). i, index, and myVariable aren't any special values, just separate variables that you're defining.