I have long used the i/j/k naming scheme. But recently I've started to adapt a more consequent naming method.
I allready named all my variables by its meaning, so why not name the loop variable in the same deterministic way.
As requested a few examples:
If you need to loop trough a item collection.
for (int currentItemIndex = 0; currentItemIndex < list.Length; currentItemIndex++)
{
...
}
But i try to avoid the normal for loops, because I tend to want the real item in the list and use that, not the actual position in the list. so instead of beginning the for block with a:
Item currentItem = list[currentItemIndex];
I try to use the foreach construct of the language. which transforms the.
for (int currentItemIndex = 0; currentItemIndex < list.Length; currentItemIndex++)
{
Item currentItem = list[currentItemIndex];
...
}
into
foreach (Item currentItem in list)
{
...
}
Which makes it easier to read because only the real meaning of the code is expressed (process the items in the list) and not the way we want to process the items (keep an index of the current item en increase it until it reaches the length of the list and thereby meaning the end of the item collection).
The only time I still use one letter variables is when I'm looping trough dimensions. But then I will use x, y and sometimes z.