DEV Community


Discussion on: Stop Using "data" as a Variable Name

cubiclesocial profile image

I've never understood why people use i and j for loop variable names. I prefer x, y, and z because they are generally used for looping spatially over an array (columns = x, rows = y, depth = z). Using x, y, and z also mirrors the Cartesian-like planes in mathematics fairly well. That is, anyone with a strong math background will understand x, y, z, and n intuitively while i and j are largely meaningless with i being used for imaginary numbers. i and j and l (lowercase L) are also the thinnest characters in many fonts, making them harder to read.

Thread Thread
drumstix42 profile image

Check out this Answer on StackOverflow:

The answer is mostly because of Math, and what "i" and "j" stood for and it's pretty easy to understand how it made it's way into code. Luckily these days, simple "for" loops can be often be replaced with functional versions, or use "for...of"