Why are variables “i” and “j” used for counters?

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.

Leave a Comment