

Why are variables “i” and “j” used for counters? - marcog1
http://stackoverflow.com/q/4137785/89806

======
davewiner
Dates back to Fortran, a language that was designed primarily to work on real
numbers, for scientific calculation. They needed whole numbers or "integers"
-- but they didn't have the concept of type declarations yet (or it was a
hodgepodge and non-standard) -- so they came up with a convention that
variables whose names began with i through (some upper bound I don't remember)
were integers.

Since loop indices are integers it made sense that their names should begin
with I. If your outer loop's variable is named I and you all of a sudden need
an inner loop, what are you going to name it? J of course. Which is how this
convention began.

Obviously today's programming languages not only allow you to declare the
types of variables, many of them support variable types depending on what's
been stored in a variable. But this was at the dawn of the computer era,
before such coolness had come about.

~~~
tzs
> Dates back to Fortran...

I would expect it is far older than that. Mathematicians and others of that
ilk have long used i, j, and k when writing sums using the capital sigma
notation (and when writing products using the capital pi notation).

Fortran almost certainly acquired it from that.

------
RiderOfGiraffes
Dup: <http://news.ycombinator.com/item?id=1971507>

Many comments there.

