Hamilton was really influential, and quaternions were the standard way to do 3D analysis before 1900. By then, mathematicians were used to thinking of (ijk) as a matched set.
Vector calculus replaced quaternionic analysis in the 1890s because it was a better way to write Maxwell's equations. But people tended to write vector quantities as like this: (3i-2j+k) instead of: (3,-2,1). So (ijk) became the standard basis vectors in R^3.
Finally, physicists started using group theory to describe symmetries in systems of differential equations. So (ijk) started to connote "vectors that get swapped around by permutation groups," then drifted towards "index-like things that take on all possible values in some specified set," which is basically what they mean in a for loop.
What variable did mathematicians use for summation before physicists started using group theory to describe symmetries in systems of differential equations? Isn't that a fairly recent development?
My search for an old paper with a bloody summation symbol found nothing. I did, however, find this OT gem about Newton, written in 1848:
From the thick darkness of the middle ages man's struggling spirit emerged as in new birth; breaking out of the iron control of that period; growing strong and confident in the tug and din of succeeding conflict and revolution it bounded forwards and upwards with resistless vigour to the investigation of physical and moral truth; ascending height after height; sweeping afar over the earth, penetrating afar up into the heavens; increasing in endeavour, enlarging in endowment; every where boldly, earnestly out stretching, till, in the Author of the Principia, one arose, who, grasping the master key of the universe and treading its celestial paths, opened up to the human intellect the stupendous realities of the material world, and in the unrolling of its harmonies, gave to the human heart a new song to the goodness, wisdom, and majesty of the all creating, all sustaining, all perfect God.
FORTRAN's system of giving default types based on the first letter of a variable name gives rise to the old joke, "God is real... unless declared integer".
Reason being, on the ZX Spectrum, it had all the BASIC keywords on each key, and pressing the key would input the keyword itself (depending on where you were etc). The 'N' key had 'NEXT', and the 'F' key had 'FOR'.
So to type 'next n' you just pressed 'N' twice. Typing in 'for f' you pressed 'F' twice.
This is correct. I assure you that the physics texts all tend to use i and j as index variables. Particularly for matrices, whose terms have a tendency to be written as M_i_j. [1]
Remember that modern electronic computing was invented by mathematicians and physicists.
---
[1] HN isn't about TeX, so read that as "M sub-i sub-j".
Next question: what other single character variable names do people use? I've always wanted to work up a master list somewhere.
Speaking to my own usage, I use i and j for indices, x, y, and z for Cartesian coordinates, n for "number", k and v for "key" and "value" when iterating through a hash, and r for a variable I'm using for a return value later on.
A t for a type variable. I sometimes name variables to the data structure that they are holding, e.g. p for pair, h for heap. The names x, y and z for things that have a generic type, and xs ("axes"), ys ("whys"), zs ("zeds") for collections of general things (and xss for collections of collections of things).
For example, an F# pairing heap:
type 't heap = Empty | Heap of 't * 't heap list
let findmin (Heap(x,_)) = x
let merge h1 h2 =
match (h1,h2) with
| Empty,h | h,Empty -> h
| Heap(x,h1s),Heap(y,h2s) -> if x < y then Heap(x,h2::h1s) else Heap(y,h1::h2s)
let deletemin (Heap(_,hs)) = List.fold merge Empty hs
let insert h x = merge h (Heap(x,[]))
First line: t for type. Second line: x for something of generic type t. Third line: h1 and h2 for heap. Fifth line: h1s and h2s for lists of heaps corresponding to h1 and h2. This saves time coming up with names, and it ends up being more readable if you're used to it. Of course these short names will only be used for variables that are used internally in a function, not for function names and such.
I use a description of what I;m iterating over. If it's a list of people, I use 'person'. If the keys are session IDs, I use 'sessionid'. I do this because it's easier for me and I think I'm being nicer to the next person to come along.
I use 'i' for 'index' / 'iterator', j because it follows i, and k because it follows j. The first time I wrote a double-deep loop, the only ones I could recall having seen had used x and y, because they mapped to x,y coordinates.
So why don't I use x and y where it's not coordinate based? Weaker fingers. 'X' is inherently much harder to hit than 'i', 'i' serves as a mnemonic as it's usually referring to the index being accessed, and 'y' takes a larger movement than 'j'.
I don't agree that the question changes. I would argue that the fact that Fortran enshrined the convention is a more relevant answer than the answer to why Fortran picked that range. The reason being that the answer to the latter question is most likely from another domain, such as Mathematics.
Although I do find the answer to the latter question interesting as well, just not as interesting as the answer to the first.
Because mathematicians, physicists, and engineers use i through n for integers in their mathematical formulas, and Fortran was their FORmula TRANslator into computerese. (Additional fun fact: They begin their matrix row and column counts with 1, which is why Fortran array indices start at 1.)
Not only prefixed, I barely remember my grandfather telling me a story about a thousand years ago identifiers where so precious, they were only ONE char long, from A to H were asigned to strings, from I to P were for integers and the rest for floats.
When I first learned programming, the tradition was to use 'f' and 'n'.
On the ZX81, the "FOR" command was accessed by pressing the F key in a special "command mode", so by typing the F key twice you got "FOR F". Similarly "NEXT N".
I rarely use i-j-k, I tend to use n-m-r for some reason(possibly because I've been programming with iterator syntax so long, that I always think first of grabbing "thing n" rather than incrementing "counter i.") But on reflection I think this is probably less legible.
For me i has always been "iterator variable" or something similar, j being the logical next iterator variable. Then again I haven't done this (code) for very long.
Euler picked i for the imaginary unit.
Hamilton needed two more square roots of -1:
Hamilton was really influential, and quaternions were the standard way to do 3D analysis before 1900. By then, mathematicians were used to thinking of (ijk) as a matched set.Vector calculus replaced quaternionic analysis in the 1890s because it was a better way to write Maxwell's equations. But people tended to write vector quantities as like this: (3i-2j+k) instead of: (3,-2,1). So (ijk) became the standard basis vectors in R^3.
Finally, physicists started using group theory to describe symmetries in systems of differential equations. So (ijk) started to connote "vectors that get swapped around by permutation groups," then drifted towards "index-like things that take on all possible values in some specified set," which is basically what they mean in a for loop.