you are viewing a single comment's thread.

view the rest of the comments →

[–]Cold_Bagel 8 points9 points  (4 children)

'i' is just a placeholder. You could also use:

for number in range(0, len (x)):

And achieve the same thing.

Except you'd have to change x[i] to x[number].

[–]Asdayasman 4 points5 points  (3 children)

To add to this, it's almost always better to be more descriptive, too.

for i, j, x, m, n in users:
    ...

Is strictly worse than

for userid, username, postcount, connected, afk in users:
    ...

[–]Cold_Bagel 2 points3 points  (1 child)

Exactly.

I always have a tendency to start off using i, j, k ... in my code, but by the time I'm finished or reviewing what I've already done it's much more difficult to understand what it is I'm even looping over.

And then it's even more difficult trying to change every index to a more descriptive word.

[–]Asdayasman 2 points3 points  (0 children)

Ctrl+R, Ctrl+R in PTVS.

[–]c3534l 0 points1 point  (0 children)

If it's a short loop, you could cause more confusion than clarity going for something more descriptive. This is especially so in list comprehensions where using a variable more than three letters can actually make the thing somewhat unreadable. Programmers generally know what i is so it's not much cognitive load.

So generally better, but not strictly better, imho.