Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Possible Duplicate:
Why do most of us use 'i' as a loop counter variable?

Maybe this questions seems to be extreamly stupid but I wonder why we use i as variable in most cases in for loops (and not other letter). This might be a historical cause.

eg.

for(int i = 0; i < 10; i++)
share|improve this question
    
In my O'Reilly ABC book, i is for int –  James Aug 19 '11 at 13:50
    
By the way, I prefer ++i to i++ ;-) –  FredOverflow Aug 19 '11 at 14:53
2  
I prefer to use me –  CamelBlues Aug 19 '11 at 18:02
add comment

migrated from stackoverflow.com Aug 19 '11 at 13:51

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Anna Lear Aug 19 '11 at 14:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4 Answers

Long ago there was a programming language called FORTRAN, indeed the first so called higher programming language. In FORTRAN variables names beginning with i,j,k,l,m,n were implicitly declared of type INTEGER. So i can stand for:

  • integer
  • index (of an array, like in a[i])

or other things. Short names are typed quickly, so i is a good choice for a loop counter.

The FORTRAN convention goes deeper. Mathematicians love to name integer variables i,j,k,l,m, or n. They often use a,b,c,d,e,f for constant values and x,y,z for variables.

share|improve this answer
add comment

In FORTRAN IV, the variable names I-N were implicitly assumed to be integers. I think it's part of FORTRAN's legacy as a scientific computing language. Linear algebra uses integer indexes to derefence values in vectors and matricies. The convention diffused into other languages.

share|improve this answer
add comment

I guess the i stands for index.

Long ago, when computers were not that fast and memory and storage space was expensive, it was important to keep your source code small, so that it would fit in memory and the compilation process would run faster. Those things are not true anymore with today's computers, but still the i as the first index variable name stuck.

share|improve this answer
add comment

For what it's worth, I never use i. Perhaps this is a byproduct of using simpler text-editors, rather than IDEs, but I find it makes it very difficult to scan through a routine looking for places where the variable is used. To see what I mean, try searching for all the places i exists on this page, and seeing which ones refer to it as a variable, and which are incidental.

I always use more meaningful names, like

for(int Index = 0; Index < 10; Index++)
{
    // do something
}
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.