• @soloner@lemmy.world
    link
    fedilink
    711 months ago

    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.

    • @mlc894
      link
      011 months ago

      Is it for “index” or “iterator”?

      • @soloner@lemmy.world
        link
        fedilink
        111 months 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.