4 ms·
"i" as in a counter is almost a standard for any code in any programming language. "i", "j" and "k" (comes from math). If you have the loop counter as "node", t
by inerte 15y ago
"i" as in a counter is almost a standard for any code in any programming language. "i", "j" and "k" (comes from math). If you have the loop counter as "node", then you're doing it wrong, but if you have an actual node, then it's ok.
- kstenerud 15y agoOr, if you want to be sure that a search/replace of a name won't go awry, you could use names such as customerIdx, nodeIdx, accountIdx. It also helps keep things clear in the few cases where you find yourself with nested iterations (so that you don't accidentally call customers[j] when it should have been customers[i]).
- greggman 15y agoI no longer use i as a counter because a few times in my career I've mistaken i for 1 or l.
- mattdeboard 15y agoIf I've got an iterable of Foo object instances, I'll call it "foos". When I iterate, I'll write "for foo in foos" without exception. Calling it i, j or k is fine, too, but I try to be as obvious as possible, because I believe that is a virtue.