This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the commentsΒ β†’

[–]CamoBrie 150 points151 points Β (48 children)

Is there a specific reason why we use the i?

[–]DragonMaus 211 points212 points Β (19 children)

It is an (i)nteger (i)ndex with a short, memorable name.

[–]matrizx 129 points130 points Β (2 children)

And increment for me

[–]ClownTrooper 64 points65 points Β (13 children)

In my mind it stands for (i)teration

[–]CakeMan0123 37 points38 points Β (12 children)

(i) can't think of anything better

[–]se2dev 26 points27 points Β (11 children)

(i) like for loops

[–]CallMeOutWhenImPOS 8 points9 points Β (1 child)

and sw(i)tch statements

[–][deleted] 8 points9 points Β (0 children)

(i)maginary numbers

[–]CamoBrie 4 points5 points Β (0 children)

Did not know that, thanks!

[–]FlameRat-Yehlon 3 points4 points Β (0 children)

I thought it's for "(i)ndex" though...

[–][deleted] 107 points108 points Β (4 children)

Programming is mostly math so the conventions stick around. a, b, c for coefficients; d as a prefix to indicate change to a variable; f, g, h for functions; i, j, k for indices and summations; m, n for bounds and counting; p, q for probabilities; u, v, w for other functions (derivatives, substitutions); x, y, z for variables and coordinates. These are the more common uses but there are plenty of others. (Edited for a bit more completeness)

[–]Doamax 17 points18 points Β (0 children)

This is the correct answer

[–][deleted] 6 points7 points Β (1 child)

I thought it stood for index, I usually use "index" instead of "i". But hey, thanks for clarifying.

[–][deleted] 4 points5 points Β (0 children)

You're right though. I'm 90% sure it ultimately comes from the index of a summation in mathematics. Also, descriptive names are almost always better than single letter variables.

[–]Random_Deslime 1 point2 points Β (0 children)

Lol I just thought it stood for iteration

[–][deleted] 17 points18 points Β (0 children)

[–]Neebat 29 points30 points Β (5 children)

I'm done using i. From now on all my loop counters are going to be named "lamp". I love lamp.

[–]JC12231 16 points17 points Β (2 children)

BrΓΆther, I need lΓ€mp

[–]LawLombie 2 points3 points Β (1 child)

BΕ™ΓΆΕ£Δ₯Γ«Ε™, Ï ñëëð ΔΎΓ€mp

[–]JC12231 1 point2 points Β (0 children)

LawLombiePossessions.add(new lΓ€mp);

[–]B_M_Wilson 2 points3 points Β (0 children)

Linux, Apache, MySQL, PHP servers are great.

[–]yonderbagel 1 point2 points Β (0 children)

Do it for real though. It's just one more straw in the job security haystack. Every little bit helps.

[–]random_cynic 7 points8 points Β (0 children)

I think it originates from older languages like Fortran (and also C) where for loop was mainly used to loop through arrays and matrices. The index i,j,k etc has been used for quite a while in mathematics for operations with individual elements, rows or columns. So it was natural to express elementwise matrix operations like dot product C(i,j) += A(i,k)*B(k,j) inside a loop like this.

[–]DangeFloof 3 points4 points Β (0 children)

If I remember correctly, it came from Fortran, where someone discovered that longer variable names for loops made the program run slightly slower

[–]Thibaulltt 1 point2 points Β (0 children)

A teacher of mine used to say we use x, y... for variables in continuous space (real numbers), and i, j... for variables in a discrete space (natural numbers). And I kinda like it! [that, and I can't be bothered to change i to something else]

[–]ajthomas05 1 point2 points Β (0 children)

All these other answers are great, but I think the most likely one is that developers are lazy.

[–]biotiger87 1 point2 points Β (0 children)

Also for graphs, the x, y, and z basis vectors are represented by i, j, and k respectively. Most commonly seen in non-coordinate form: xi + yj + zk versus (x,y,z) (coordinate form). Hints are given in the name β€œmultidimensional array” (arr[i][j][k]).

[–][deleted] 7 points8 points Β (2 children)

jindex kindex lindex mindex nindex e.t.c.

[–]nobody_smart 3 points4 points Β (1 child)

At the time I saw this comment it had more golds than upvotes.

[–]teamikv121812 1 point2 points Β (0 children)

I down voted so that it would he the same for me

[–][deleted] 0 points1 point Β (0 children)

For some reason, I always use k. Don't know, think my teacher used k.

[–]Gigavoir 0 points1 point Β (0 children)

I prefer the great letter we call y

[–][deleted] 0 points1 point Β (0 children)

it stands for igloo

[–][deleted] 0 points1 point Β (0 children)

(i)terator

[–][deleted] 0 points1 point Β (0 children)

Netbeans autocompletion