Why are i and j (and sometimes k) used in loops? Blame Fortran (I think). Here’s why


It came up today that i and j are used for variables in loops. The reason for that likely has to do with Fortran. As this piece (Fortran – Implicit variable types | fortran Tutorial) explains:

When Fortran was originally developed memory was at a premium. Variables and procedure names could have a maximum of 6 characters, and variables were often implicitly typed. This means that the first letter of the variable name determines its type. variables beginning with i, j, …, n are integer everything else (a, b, …, h, and o, p, …, z) are real

I used to program in older versions of Fortran (in the early 80s) and we automatically used i and j for variables and loops. Likely it carried over into other languages too. For example, I have an early edition of The C Programming Language book and they use i for some of their loops (page 20).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.