PDA

View Full Version : i j k variable names

swgh
10-10-2006, 01:36 PM
Am I correct in the face programmers use I J and K as variable names for for loops since the FORTRAN language? Was the language designed to accept only these variables?

twomers
10-10-2006, 01:39 PM
I use i, j, k out of habit, and always assumed i stood for iterator or something and that j and k followed suit alphabetically. I don't know about the fortran link ... but I couldn't see any language accepting only three variables!

System_159
10-10-2006, 02:45 PM
If the variables are loop specific, then I use i,h,j, and k mostly. i is just for interger/iterator really, the others are just near it in the alphabet.

Perspective
10-10-2006, 04:30 PM
Check any math book/paper, you'll see i, j, and k are pseudo standards for indices on summations, integrals, etc... I'm pretty sure math predates computers.

Wraithan
10-10-2006, 04:36 PM
I am with Perspective, it has been in math for a lot longer than computers have been around.

One reason you see a lot of it though, is habbit, some programmers who are newer, or even ones that have been doing it for a while, learned to use i in loops, and if you have nested loops j, k, and so on.

I don't even think about it anymore, when I go to do a for loop or while loop

for(int i = 0; i < value; i++) {
int j = 0;
while(j < 100) {
/*stuff that changes j in more/less than +1 per loop */
}
}

Pobega
10-10-2006, 04:39 PM
I've never even heard of people using i, j and k as variables for anything. I'm used to seeing variable names like count or x for loops.

psychopath
10-10-2006, 05:02 PM
I've seen names like 'idx' or 'iter' used occasionally, but usually i, j, k, etc.

pianorain
10-10-2006, 05:45 PM
I use i, j, k on the first pass. After that, I'll substitute a more meaningful name so that I don't have to wonder why I've got i+j*60 somewhere in my code.

CornedBee
10-10-2006, 06:58 PM
Agree with those that say it comes from mathematics, and want to add that 'i' derives from index, not integer or iterator.

Mario F.
10-10-2006, 07:03 PM
I use i, j, k for iterations or simple short lived flag-like variables when it makes sense. To me. Which probably not always makes sense to others. I'm also known to use n and m. Usually when I want to convey limits on dimensions or sizes

Rennor
10-11-2006, 12:28 AM
As a beginner I used to use x mostly and then y and z. When starting to write some 2D gfx effects those quickly changed to i, j and k since x,y and z are for coordinates :)

Then the mixture was complete, sometimes i, j and k were just for looping, sometimes they represented "temporary" variables where x = i, y = j and z = k.

Go figure.

Nowadays I use only i when I try out something quickly, if I need more variables they usually come out with proper names. Being professional and responsible for quality makes me automatically name everything and comment them properly according to our styleguides :)

swoopy
10-11-2006, 05:03 PM
Am I correct in the face programmers use I J and K as variable names for for loops since the FORTRAN language? Was the language designed to accept only these variables?
By my thinking, you are correct. In FORTRAN, variables that begin with the letters I thru N are by default of type INTEGER. Variables that begin with any other letter are by default REALs. So you can see how this would have led to using I, J, and K for for-loop indices.

maxorator
10-12-2006, 01:34 AM
I usually use I, N and E. I don't know why.

dwks
10-12-2006, 04:25 PM
I use x, y, and z (and a, b, c etc if required). If I need to use coordinates, I use xp, yp, etc (for X-position, Y-position). I don't know why, either.