why i

Duncan Booth me at privacy.net
Tue May 25 04:08:46 EDT 2004


Ben Finney <bignose-hates-spam at and-benfinney-does-too.id.au> wrote in 
news:slrncb5s1p.21a.bignose-hates-spam at rose.localdomain.fake:

> On Tue, 25 May 2004 08:10:51 +1000, mr_vocab wrote:
>> 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.

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.



More information about the Python-list mailing list