
Why we use i, j, and k in for loops - nickb
http://tech.ablegray.com/article/why-we-use-i-j-and-k-in-for-loops
======
pg
Surely Fortran merely copied existing math conventions.

~~~
hhm
That was exactly what I was thinking. n is used for naturals, i, j and k are
used for variable values in sums, for example (which, when programmed, would
require the use of "for" loops).

~~~
pixcavator
Does i stand for 'integer' or possibly 'index'? I also wonder how far into the
past it goes, 19 century?

~~~
hugh
Like so many other things in mathematics, I suspect it goes back to Euler
(18th century). He invented the capital-sigma notation for sums, although I'm
not sure what letters he used for his indices.

The use of x, y and z as unknown reals goes far as back as Descartes. I don't
know what he used for integers though, or whether he bothered to distinguish
integers from reals.

------
DaniFong
Clearly it is in deference to D i j k stra. ;-)

~~~
Xichekolas
Yeah... he had such an awesome name for who he turned out to be.

------
tlrobinson
Errr... i, j, k are often used in mathematical proofs in summations and things
like that... are we sure that's not why Fortran used them in the first place?

Which came first, the chicken or the egg? Math or Fortran?

------
axod
I learned to program on the ZX Spectrum (Awesome home computer). The spectrum
had a great(ish) keyboard, where each key also had about 3 or 4 BASIC
shortcuts on it, which you could get with various shift keys. Also it would
recognize when it was expecting a statement, and just use the statement for
that key instead of the letter.

For example, to type "for f", you would press the 'f' key twice, as it had the
shortcut 'For' on it, and also was the letter f. Similarly, to type "next n",
you'd hit the 'n' key twice.

Perhaps why you sometimes see f and n in for loops.

------
te_platt
I always thought it was because programmers were too lazy to write a couple of
extra characters to make a nice descriptive variable name. At least that's why
I do.

~~~
kingnothing
Sure, we are... But the question is why did we arbitrarily start incrementing
from 'i' instead of 'a'?

~~~
chengmi
int i; float f; char c;

~~~
downer
__

    
    
    float    f;
     unsigned u;
     char     c;
     key_t    k;

That's how I swing, man.

------
bootload
Could it have something to do with the keyboard layout?

On standard keyboards "i" is just above "j & k". Also in basic typewriter
tuition, your right hand apposing finger starts on the keyboard at the letter
"j" when you commence typing. "k" has your right index finger. Most people
being right handed these letters are pretty much the first & most intuitive
letters to use.

------
edw519
Wow! I did a global search for the variables "i", "j", and "k" in this 2000
line program I have to enhance, and I got all of them and a whole lot more!
What a great idea!

