why i

B

Ben Finney

i never got this its always in my tutial bookfor i in range(...)

"Index". i.e., the variable will be the index of an array you want to
iterate over.

The usage of "i" was promulgated by the FORTRAN language, which allowed
only single-letter variable names (and was all upper case, too, so it
was actually I). The FOR statement was commonly used to iterate over an
array, and I and J were the commonly used index variables for that
purpose.
 
A

Aquarion

i never got this its always in my tutial bookfor i in range(...)

It's arbitrary, but some programmers use "i" in an iteration to either
stand for iteration or index.
 
D

Duncan Booth

"Index". i.e., the variable will be the index of an array you want to
iterate over.

The usage of "i" was promulgated by the FORTRAN language, which allowed
only single-letter variable names (and was all upper case, too, so it
was actually I). The FOR statement was commonly used to iterate over an
array, and I and J were the commonly used index variables for that
purpose.

Close, but not quite there.

Early versions of Fortran supported variable names up to 6 characters long.
Actually, Fortran always allowed longer variable names, but only the first
6 were significant. I believe the reason why it was 6 characters was that
with a 36bit word length and 64 characters in your character set (as you
say, no lower case), you could exactly pack a 6 character string into 1
machine word.

The actual reason why everyone uses I and then J as the for loop indexes
was that Fortran, by default, assumed all variables starting with letters
from I-N were integer, and all other variable names were real. Integer
names starting with I was presumably chosen for its mnemonic value and the
other letters then follow on in sequence, presumably far enough for what
the original language designers thought was a reasonable 20:6 split real to
integer variables.

Obviously you are going to pick some really meaningful :^) 6 character name
for that all important linear-regression library function but for a simple
loop, why bother.
 
P

Peter Hansen

Duncan said:
The actual reason why everyone uses I and then J as the for loop indexes
was that Fortran, by default, assumed all variables starting with letters
from I-N were integer, and all other variable names were real. Integer
names starting with I was presumably chosen for its mnemonic value and the
other letters then follow on in sequence, presumably far enough for what
the original language designers thought was a reasonable 20:6 split real to
integer variables.

Does the FORTRAN usage precede or follow the similar common use by
mathematicians?

My guess is that subscripts i, j, k have been used so for much longer
than FORTRAN has existed, or computers for that matter.

The idea that 'i' is mnemonic for 'integer' is interesting, though.
If the mathematical field is really the origin, rather than FORTRAN,
it would be interesting to know if that was how "they" picked it.

Googling to little avail, the best I could find to help was Hilbert's
1900 address on "23 Mathematical Problems" which he gave to the Int'l
Congress of Mathematics in Paris, proving a usage which predates
FORTRAN by 50-some years. The interesting page maintained by Jeff
Miller at http://members.aol.com/jeff570/mathsym.html makes no mention
of the topic.

-Peter
 
R

Richard Brodie

Peter Hansen said:
The idea that 'i' is mnemonic for 'integer' is interesting, though.
If the mathematical field is really the origin, rather than FORTRAN,
it would be interesting to know if that was how "they" picked it.

Googling to little avail, the best I could find to help was Hilbert's
1900 address on "23 Mathematical Problems" which he gave to the Int'l
Congress of Mathematics in Paris, proving a usage which predates
FORTRAN by 50-some years.

I would assume vector algeba was the origin; Google can go back
to 1843 on that line: http://www.wordiq.com/definition/Quaternion

That suggests that i, j, k notation is an extension of complex notation
so i must be the Euler i (1777) presumably standing for imaginary.
 
P

Peter Hansen

Richard said:
I would assume vector algeba was the origin; Google can go back
to 1843 on that line: http://www.wordiq.com/definition/Quaternion

That suggests that i, j, k notation is an extension of complex notation
so i must be the Euler i (1777) presumably standing for imaginary.

I'm not sure we should consider that early usage to be of
the same type. The Hilbert usage is as a subscript, which
corresponds to (I think) the reason for using i,j,k as indices
in a program loop: to index into a vector, as in M and such.

-Peter
 
G

Grant Edwards

The actual reason why everyone uses I and then J as the for loop indexes
was that Fortran, by default, assumed all variables starting with letters
from I-N were integer,

That that was because people always used i,j,k as indexes.
 
D

Dennis Lee Bieber

The usage of "i" was promulgated by the FORTRAN language, which allowed
only single-letter variable names (and was all upper case, too, so it

That must have been a really old version of FORTRAN -- all
versions I've encountered allowed for, at least, 6 significant
characters in variable names. (This goes back to F-IV/F-66). BASIC was
limited to one or two characters.

I think, at least on my college machine, part of the limit was
that the back-end assembler stage only accepted 8 characters, and the
compiler tended to prefix the FORTRAN variables with special markers.

However, FORTRAN had the "Indian" <G> {my mnemonic for the
range} -- the default for undeclared variables beginning in the range I
... N is INTEGER. A .. H, O .. Z are REAL/FLOAT.

--
 
S

Steve Holden

Dennis said:
That must have been a really old version of FORTRAN -- all
versions I've encountered allowed for, at least, 6 significant
characters in variable names. (This goes back to F-IV/F-66). BASIC was
limited to one or two characters.
[...]
I think the original author was confusing Fortran and BASIC. I used
Fortran II back in 1968, and that definitely allowed six-character names.

regards
Steve
 
B

Ben Finney

That must have been a really old version of FORTRAN -- all versions
I've encountered allowed for, at least, 6 significant characters in
variable names. (This goes back to F-IV/F-66). BASIC was limited to
one or two characters.

Yes, I've since been corrected; FORTRAN allowed at least 6 characters
for variable names.

I was confused by my memory of the "I through N" rule of FORTRAN's
integer/real split; for some reason that translated into erroneously
thinking the variables were only one character in length.

I'm in agreement with others that FORTRAN was, in this regard, influeced
by the existing mathematical formula convention of 'i', 'j', 'k' etc.
for vector subscripts. Since FORTRAN, as the language name indicates,
was initially used for mathematical formula algorithms, the use of a FOR
loop to iterate through a vector (or array) was common, and thus using
the variable I for the index would seem natural to a
mathematically-oriented programmer.
 
G

Greg Ewing

Dennis said:
However, FORTRAN had the "Indian" <G> {my mnemonic for the
range} -- the default for undeclared variables beginning in the range I
.. N is INTEGER. A .. H, O .. Z are REAL/FLOAT.

Hence the well-known saying, "GOD is REAL, unless
declared INTEGER."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,048
Members
47,647
Latest member
NelleMacy9

Latest Threads

Top