Why are variables "i" and "j" used for counters?

Carlos picture Carlos · Nov 9, 2010 · Viewed 84.5k times · Source

I know this might seem like an absolutely silly question to ask, yet I am too curious not to ask...

Why did "i" and "j" become THE variables to use as counters in most control structures?

Although common sense tells me they are just like X, which is used for representing unknown values, I can't help to think that there must be a reason why everyone gets taught the same way over and over again.

Is it because it is actually recommended for best practices, or a convention, or does it have some obscure reason behind it?

Just in case, I know I can give them whatever name I want and that variables names are not relevant.

Answer

zwol picture zwol · Nov 9, 2010

It comes ultimately from mathematics: the summation notation traditionally uses i for the first index, j for the second, and so on. Example (from http://en.wikipedia.org/wiki/Summation):

\sum_{i=1}^{n} i = \frac{n^2 + n}{2}

It's also used that way for collections of things, like if you have a bunch of variables x1, x2, ... xn, then an arbitrary one will be known as xi.

As for why it's that way, I imagine SLaks is correct and it's because I is the first letter in Index.