this post was submitted on 09 Jul 2023
629 points (94.0% liked)

Programmer Humor

32426 readers
694 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 6 points 1 year ago (1 children)

I think it's a convention taken from math notation conventions.

[–] [email protected] 7 points 1 year ago (1 children)

I is short for "index" for a traditional for loop for mapping over an array and looking up by index. J comes after I and is used for nested loops so it doesn't shadow the outer I.

[–] [email protected] 0 points 1 year ago (3 children)

Is it for “index” or “iterator”?

[–] [email protected] 2 points 1 year ago (1 children)
[–] [email protected] 1 points 1 year ago

I believe index for the classical need to iterate through an array. E.g.

for (i = 0; I <= arr.length; i++) { var thing = arr[i] ... }

So to me it stands for "index" for array lookup.

Before map and iterators were implemented in a lot of languages, this was the defacto way to iterate a list. At least this is how I learned it in java/c back in the day. Nowadays I think most OOP languages including java have implemented the "for ... in ..." Syntax or similar which deprecates this convention.