views:

536

answers:

6

Possible Duplicate:
Why are we using i as a counter in loops

I've used these myself for more than 15 years but cannot really remember how/where I picked up that habit. As it is really widespread, I'm curious to know who originally suggested / recommended using these names for integer loop counters (was it the K&R book?).

+4  A: 

The Mathematicians :)

n00ki3
+2  A: 

It's common from school-level and college-level algebra exercises (although x and y had their part to play, there, too :-)

Also, if I remember correctly, the early programming languages (like early versions of FORTRAN) used variable naming in a way where initial letters were significant, and this may have had a part to play. For example, as this page says:

A FORTRAN variable is a way of referring to a cell of the computer. Names for variables must conform to the following rules:

  1. The name may be from one to six characters.
  2. The first character must be a letter.
  3. Characters other than the first may be letters or numeric digits.
  4. If the first character is I, J, K, L, M or N, the variable is integer (i.e. can hold a whole number value). Otherwise, it is real (i.e. can hold a value according to the floating point convention).
Vinay Sajip
+9  A: 

i = integer

Comes from Fortran where integer variables had to start with the letters I through N and real variables started with the other letters. Thus I was the first and shortest integer variable name. Fortran was one of the earliest programming languages in widespread use and the habits developed by programmers using it carried over to other languages.

(From: Why are we using i as a counter in loops)

Obviously, j and k are just the next ones in your favorite alphabet.

Pukku
Maybe it was a later addition, but in FORTRAN-G at least, variables starting with I-N where INTEGER unless declared otherwise. It was perfectly legal to say "REAL IVAR" or "INTEGER A".
Paul Tomblin
+2  A: 

FORTRAN. If the first character is I, J, K, L, M or N, the variable is integer (i.e. can hold a whole number value). Otherwise, it is real (i.e. can hold a value according to the floating point convention).

Otávio Décio
A: 

From the wikipedia for Loop Counter

A common identifier naming convention is for the loop counter to use the variable names i, j and k (and so on if needed), where i would be the most outer loop, j the next inner loop, etc. The reverse order is also used by some programmers. This style is generally agreed to have originated from the early programming of FORTRAN, where these variable names beginning with these letters were implicitly declared as having an integer type, and so were obvious choices for loop counters that were only temporarily required. The practice also dates back further to mathematical notation where indices for sums and multiplications are often i, j, etc.

Falaina
+1  A: 

I always thought i stands for index as used eg in sum formulas in mathematics.

Kim