Archive - Originally posted on "The Horse's Mouth" - 2009-09-22 12:13:10 - Graham Ellis
Q: Why do people use variable names like "i" and "j" for loop counters? I thought that you were supposed to use longer, desciptive names!
A1:Fortran (FORmula TRANslator) was one of the prevalent programming languages in the 1960s and 1970s, at a time when many programming techniques, algorithms and methodologies were being developed, and in Fortran, variable names starting with I J K L M and N were implicitly integer, and all others (A to H and O to Z) implied float. So it was natural to START your loop variables - which tended to be integers as they counted up through discrete array members - with one of these default letters.
A2: Loop variables are set up and used within a very restricted (small) area of your program, but are intensively referred to within that area. Giving them a long name which you have to keep repeating leads to code that's needlessly stretched and can actually be more confusing that shorter code. Think about it ... in the wider real, we refer to our queen as "Elizabeth" but I'll bet that in the small local environment of home at WindsorSandringhamBalmoral Buck House, her Phil calls her Betty or even Bee.