• Poob@lemmy.ca
    link
    fedilink
    arrow-up
    3
    ·
    edit-2
    1 year ago

    i is for index. j is simply the next letter and we’re too lazy to think up something meaningful

  • Sam@sh.itjust.works
    link
    fedilink
    arrow-up
    2
    ·
    1 year ago

    When I’m doing coding interviews I always like to start off and say I’m a big fan of very long variable names. “As descriptive as you can be” I say. Then I get to my first for loop. Instead of i I use “iterator” and then when I start a nested loop I use “jiterator” and it always gets a laugh.

  • barsoap@lemm.ee
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    1 year ago

    It depends. x and y are either elements or coordinates, a and b usually elements though in e.g. Haskell reserved (by convention) for type variables.

    The i j k l series is reserved for indices. n m etc. are the counts of something, as such you’ll see i counting up to n. Both are due to mathematical sum notation and general mathematical convention. Random google result:

    Let x1, x2, x3, …xn denote a set of n numbers. x1 is the first number in the set. xi represents the ith number in the set.

    …if you’re using a language in which you use i often chances are you should stop coding in C and get yourself a language with iterators. Manual loops are a bug magnet.