i is for index. j is simply the next letter and we’re too lazy to think up something meaningful
jndex
kndex
lndex
I always thought it stood for iterator
i2?
ii
A useful tip I picked up was to use
iiinstead ofjfor an inner loop. It’s far more distinct thanj.If for some terrible reason you have even more inner loops you can easily continue the trend
i,ii,iii,iiii,iiiii- oriv,vif you’re feeling romanIf you have the need to nest 5 levels of for-loops, I suggest taking a step back and rethinking your approach, my friend.
Even if that other approach is just refactoring it into separate methods.
I just do i2, i3, etc
Two or three "i"s is readable, but any more and you’re counting.
I’Ve started using i, k, m, n that’s usually enough.At this point we might as well go full Roman as you suggested. MXMCIIV to MXMCCVII as indices.
When you have multiple indices you’re also bound to have multiple cardinals those indices count up to, say
foo.lengthandbar.length, sofoo_iandbar_iare perfectly legible and self-documenting. A bit Hungarian but Hungarian is good in small amounts. Unless you’re dealing withwidthandheightin which case it’sxandybut it’s not thatwidth_iwould be incomprehensible.
It depends.
xandyare either elements or coordinates,aandbusually elements though in e.g. Haskell reserved (by convention) for type variables.The
ijklseries is reserved for indices.nmetc. are the counts of something, as such you’ll seeicounting up ton. Both are due to mathematical sum notation and general mathematical convention. Random google result:Let x1, x2, x3, …xn denote a set of n numbers. x1 is the first number in the set. xi represents the ith number in the set.
…if you’re using a language in which you use
ioften chances are you should stop coding in C and get yourself a language with iterators. Manual loops are a bug magnet.deleted by creator
I’ve gotten used to using the singular form as in…
records.filter((record) => …)
Not saying this way is better but it works for me.
I do this too. I hate using just
x, because it’s so non-descriptive.
Yes! I love using x (and xs) for functions over whatever the thing is (or things are).
People who name iterators with one letter have no soul.
two letters it is then
And people who iterate over 3D space using firstDimensionIndex, secondDimensionIndex, and thirdDimensionIndex instead of x, y, z have no sense 😜
x, y, and z are absolutely fine for spatial addressing.
I generally use a for each type loop or a map because I am usually applying some function across a collection, and in both cases I use the singular name from the collections plural.
’Cities.map(city -> …)’
For (val city in cities)
If I actually need the index for some reason I still prefer loop structures that give me the index and the item together
*note syntax pulled out of my head and not necessarily belonging to any specific language.
For ( city, index in cities)
cities.map((city, index) -> … )
If I need to double loop a matrix array I would use rowIndex and ColIndex for the indexes.
I find it hard to read when these are together:
- i, j, l
- n, m, u, v, w
From all the possible character combinations, somehow the lookalike combinations are among the most popular. Yes, probably comes from math. I hated it even more when my math prof’s i and j on the board were indistinguishable.
It’s my understanding that i,j are conventionally used in mathematics which carried over into programming, but specifically it comes from Fortran in which all integer variables start with “I” through “N” based on said mathematical convention
for <thing> in <amount> do...I don’t like i and j since they are commonly used for imaginary numbers. I like to start on n. Probably because I do DSP.
deleted by creator
WTF, I have never used nor seen “j.”
I don’t usually have to name these variables these days though. Pretty much everything I use has foreach or some functional programming type stuff.
And like that, the off-by-one mistakes disappear.
jis for a loop in a loop.
chuckles in Python
I started using the first letter of the thing I am iterating over. This is particularly helpful with nested loops so I can easily remember which index variable corresponds to which thing.
don’t mind
ibut personally always useindexorx, y, zfor gamesWhen my brain doesn’t work I’ll resort to naming them the single of the plural. Like keys turns into key when i don’t wanna call it “objkey” or “outrageouslylongnamethatmayormaynotbeafittongwordtodescribeakey”









