The Lounge is rated PG. If you're about to post something you wouldn't want your
kid sister to read then don't post it. No flame wars, no abusive conduct, no programming
questions and please don't post ads.
I think it comes from Fortran, where, at least originally, the letter defining a variable also defined its type. Any variable starting with I,J,K,L,M, or N represented integers. i & j, being the first of these, just followed through from there.
It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.
To add to what the others said about FORTRAN default variable types, variable names were limited to 6 characters as well so short variable names were a good idea. It was a convention that "generic loop counters" were I, J, and K (no lower case in those days, either!)
In addition, lines were limited to 80 characters of which the first 6 where for label numbers, used to target lines with GOTO and suchlike flow control; and the seventh was for a "Continuation character" which allowed you to use more than 72 characters in your code statement.
Short names were a good idea in those days!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
It might have come from FORTRAN, but "i" was also used for short of "index". When using nested loops the next letter was the most obvious ("j", "k", ...)
For me personally it makes perfect sense in some way. If you see a one letter variable in code, there is almost a 100% chance that it is a loop variable. Also a one letter loop variable in an array indication (some_array[i]) is easier readable than (some_array[index]). (though that is perhaps personal taste)
The designers of FORTRAN used I,J,...etc. because FORTRAN was designed for FORmula TRANslation and a lot of the language development came from having to process this linear algebra. So when the Integer variables were defined it was natural to use I and J, etc.
So which came first the chicken or the egg?
- I would love to change the world, but they won’t give me the source code.
Last Visit: 31-Dec-99 18:00 Last Update: 26-Apr-17 6:00