Programmer Convention: Why i and j in Loops

💡 Ever wondered why programmers always use i and j in loops? It’s not random — it’s tradition. Back in the early days of programming and mathematics, variables like i, j, k were commonly used as index counters. Over time, this became a universal convention followed across languages like C, Java, Python, and more. 👉 i → first loop 👉 j → nested loop 👉 k → deeper levels Simple, consistent, and instantly recognizable. And now? It’s basically… the law 😄 But here’s the real takeaway: Good code isn’t just about making it work — it’s about making it readable and understandable for others (and your future self). 📌 Use meaningful variable names when needed 📌 Follow conventions where they improve clarity 📌 Write code like someone else will read it (because they will) #Programming #Coding #SoftwareDevelopment #CleanCode #Developers #TechHumor

  • No alternative text description for this image

There's a reason behind this: Earlier when programming where in it's initial stage programmers used mathematics convenctions like i,j,k were used in Matrices then it evolved and in FORTRAN i,j,k..n were integers by default so they were easy to use then it Carry forwarded in C and C++. Mathematicians choose specifically because they wanted to use the less used words as a,b,c were generally used for constants and x,y,z for variables Hence they choose i,j,k they were rarely used then it's became tradition

I think this comes from vector notation, where we use i, j, and k to represent unit vectors along the x, y, and z axes.

The precedent was set by Fortran being the only programming language available for numerically oriented programming in the 1950s, combined with the source code having to be represented by little holes in a punched card. The punched card layout demanded a very compact representation. They wanted a way to discriminate between integers (like loop counters) and floating point numbers, without requiring any more holes. So they invented a convention that variables that started with i, j,k etc were by definition integers and the compiler implemented that in the generated machine code.

Sitting here silently watching what you would use after 18 nested layers.

So i variable means (i) iteration , that we perform each time in loop & so we can't use same (i) again and again so we use next letter j instead of i

Mathematician use x we use i,j 😅

Just like "Hello world" and Linq uses x, we can't break the laws.

"i" for Iteration and "j" comes after "i".

So ... is that i for imaginary, i for a unit vector, i for an iterator, or i for an index? Asking for a friend? What if you need to index imaginary, unit iterators?

See more comments

To view or add a comment, sign in

Explore content categories