|
probably i -> row and j -> column then
|
|
|
|
|
Hmmmmm...
|
|
|
|
|
I think you are right. If not otherwise defined FORTRAN would default to integer variables whose names started with "I" through "l" (ell) I believe. Not too sure about the ending letter as all *good* programmers defined their variables.
After years of programming I still use "t" for temporary variables (like creating a value for the debugger to see) and "t.t" for file names for the same sort of thing - temporary names while developing. This comes from the old TRS80 system.
Old habits die hard, eh?
|
|
|
|
|
|
WPerkins wrote: If not otherwise defined FORTRAN would default to integer variables whose names started with "I" through "l" (ell) I believe...
Right, and this spawned the expression "God is real (unless declared integer)".
--
Harvey
|
|
|
|
|
I just asked Him, he said "Don't Fret It, Dude".
Amazing how much hold over there is. IBM PCs in the mid 1980s had screens that were 25 rows by 80 columns... same dim as punch cards.
I wonder how much hold over we've gotten from APL and ADA - even those of us who never wrote any APL or ADA.
Topic for another thread perhaps.
I am currently working on a big project in Delphi 7 - circa 2005 code. I thought Pascal had died about the same time as Milli Vanilli... guess not.
Disco rocks, by the way.
|
|
|
|
|
I always use index and sometimes preppend it with the object or value i am indexing. It leads to a bit more verbose code but it is a hell of a lot easier to understand. Just my opinion.
|
|
|
|
|
Yes, it started in FORTRAN and leads to the following joke:
God is real unless declared integer
At least now you have the context so you can see the humor
|
|
|
|
|
Sorry, I still don't see the humour!
(Sound of tumbleweed blowing)
|
|
|
|
|
Since I, j, k, l are int by default, a variable named God would, by default, be a 'real' number - ie, floating point. You'd have to declare the variable God to be an integer in order for it to be taken that way.
Yes, this is probably a good candidate for the most delayed response ever.
|
|
|
|
|
mc42 wrote: Yes, this is probably a good candidate for the most delayed response ever.
It did take me a while to get the context there. Thanks for explaining.
It does tickle me that an Imaginary being defaults to Real, while i is definitely not imaginary. Mathematicians would shudder.
(Edited for grammar)
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
In my mind, it was because of FORTRAN. Back in the day, we didn't have all that many languages to choose from and most of us wrote in 360 assembler, FORTRAN, or COBOL. As others have said, while FORTRAN did have typing, variables starting with i-n were defaulted to integers so we just used i - followed by j, k, l in nested loops - for simplicity.
We also used foo, foobar, and jane for "temp" variables. foo and foobar were common for IBM programmers and jane was common in DEC code.
|
|
|
|
|
I've never used fortran, I always thought of 'i' as an unnamed integer. A throw-away variable.
|
|
|
|
|
now that you made me think of it, I realized of my habit of using "t" instead of "i" as my favorite looping variable. It's because I learned of FOR loops back in 1984 when typing BASIC programs on my Commodore VIC20. The user manual had several sound-effects example listings, mostly composed of a FOR T=something statement, where T stayed (I guess) for time. I typed many of them and eventually got the habit of the "t" variable.
Effects were something like this:
10 REM LUNAR LANDING EFFECT
15 POKE 36878,15
20 FOR T=200 TO 120 STEP -1
30 POKE 36876,T
40 FOR I=1 TO 100:NEXT I
50 NEXT T
(for the curious ones, 368678 was for volume "up" and 36876 for playing tone).
|
|
|
|
|
I use i because I was taught so in school, also every example in any book use i (j, k, etc.) as loop variables so I assume it seems natural to me. By the way I always thought i stood for index.
|
|
|
|
|
Yes, as others have said for many it was a carryover from FORTRAN. Nothing formal that I know of, just using i in FORTRAN and then out of habit using it in 'C' as programmers moved over to that and other newer languages.
|
|
|
|
|
When I first learned about mathematical functions f(x)(a dozen years before my first programming class) I was told mathematicians used "i" for the first incrementing variable, "j" for the next and so on.
When I started to learn programming languages, a FORTRAN professor (FORTRAN as in "FORmula TRANslation") who (of course) was a member of the Math department, said something along the lines of "This is not the theology department but using anything other that "I" for the first incremental etc is heresy. Those who want to use 'meaningful words' should consider being English or Philosophy majors and take Professor So-and-So's COBOL class."
So, 'I' as an index did not start with FORTRAN, it started before FORTRAN, but it fit nicely because those who used FORTRAN knew its meaning from math studies.
|
|
|
|
|
Yes, it is so: i, j and k are standard notation for mathematical arithmetic progressions and series.
From well before FORTRAN. But FORTRAN was designed by mathematicians, so we programmers are carrying over the notation.
a,b,c -> constants
x,y,z -> unknown terms (or real coordinates in cartesian plane)
k,j,i -> INTEGER indexes or vector coordinates.
I think Gauss was already using this conventions, more than 100 years ago.
Gauss wins. As always.
|
|
|
|
|
|
Fortran probably got it from math.
Now math... I don't know.
|
|
|
|
|
I've always used 'x'.
Why? Because a "Programming in C" book I started with used it.
So I just got used to it I guess.
|
|
|
|
|
It was also a feature of some early BASIC implementations. There were 26 variables available; A through H were floating point, I through P (??) were integers; R(??) through Z were also floating point. The only explicit type declarations were to suffix one of the single-letter variables with the $ symbol to indicate string. "I" was commonly used for loop control as being the first integer variable. It's a habit I learned in the 1960s and I still use it (very occasionally). Old habits die hard...
|
|
|
|
|
while(life!=death)
{
age++;
research++;
development++;
}
|
|
|
|
|
Hi,
Others have said this, but it deserves to be repeated:
This is classical math (handwritten, typed or printed), from a couple of centuries before the advent of computers. It's pretty natural that it was adopted by most mathematically-oriented computer languages (and, consequently, by later languages), and it also explains why it feels natural to most programmers (who have read any math - which should be a reasonable expectation) even today.
indices: i, j, k (don't remember how it goes on after that
quantities: n, m (then p, q if I remember correctly - o can be confusing).
dimensions: x, y, z, t, (xi), (eta), (theta).
I don't remember what happens when we run out of letters for indices and quantities, but if I remember correctly these sequences also continue with greek letters.
So:
for (i = 0; i < n; i++)
{
for (j = 0; j < m; i++)
{
for (k = 0; k < p; k++)
{
}
}
}
Pretty straightforward. And Newton would have understood it without thinking...
Peter the small turnip
(1) It Has To Work. --RFC 1925[^]
|
|
|
|
|
I personally use x (and y and z for nested loops - if you nest more than two levels, you need to redesign), I make it unsigned (unless there's a specific reason to use signed) because that more accurately models the real world, and I use the prefix form of the increment operator because it's potentially more efficient. So my canonical form of that construct would be:
for (unsigned x = 0; x < size; ++x)
And yes, some of my co-workers make fun of me. The ones who spend twice as much time debugging their code as I do debugging mine.
|
|
|
|