Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. i and j

i and j

Scheduled Pinned Locked Moved The Lounge
question
21 Posts 16 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mycroft Holmes
    wrote on last edited by
    #1

    Looking at Marc's early work on the commodore 64 raised the following question? Why do we seem to use i and j for loop variables? Where did it come from I wonder. And no I have not tried to google it!

    Never underestimate the power of human stupidity RAH

    M D M R T 9 Replies Last reply
    0
    • M Mycroft Holmes

      Looking at Marc's early work on the commodore 64 raised the following question? Why do we seem to use i and j for loop variables? Where did it come from I wonder. And no I have not tried to google it!

      Never underestimate the power of human stupidity RAH

      M Offline
      M Offline
      Midi_Mick
      wrote on last edited by
      #2

      I think it comes from Fortran, where, at least originally, the letter defining a variable also defined its type. Any variable starting with I,J,K,L,M, or N represented integers. i & j, being the first of these, just followed through from there.

      Cheers, Mick ------------------------------------------------ It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.

      1 Reply Last reply
      0
      • M Mycroft Holmes

        Looking at Marc's early work on the commodore 64 raised the following question? Why do we seem to use i and j for loop variables? Where did it come from I wonder. And no I have not tried to google it!

        Never underestimate the power of human stupidity RAH

        D Offline
        D Offline
        dan sh
        wrote on last edited by
        #3

        Because there is a little bit of FORTRAN in all of us?

        "It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[^]

        M 1 Reply Last reply
        0
        • M Mycroft Holmes

          Looking at Marc's early work on the commodore 64 raised the following question? Why do we seem to use i and j for loop variables? Where did it come from I wonder. And no I have not tried to google it!

          Never underestimate the power of human stupidity RAH

          M Offline
          M Offline
          Member 11683251
          wrote on last edited by
          #4

          The answer is obvious. What should be used instead? a & b? o & p? We aren't barbarians are we? i & j is just being civilized. I remember wondering about it too but didn't delve deeper than letting that thought pass. Sometimes I use a name instead if its short and descriptive otherwise I try and comment.

          1 Reply Last reply
          0
          • M Mycroft Holmes

            Looking at Marc's early work on the commodore 64 raised the following question? Why do we seem to use i and j for loop variables? Where did it come from I wonder. And no I have not tried to google it!

            Never underestimate the power of human stupidity RAH

            R Offline
            R Offline
            Ravi Bhavnani
            wrote on last edited by
            #5

            Mycroft Holmes wrote:

            Why do we seem to use i and j for loop variables?

            From FORTRAN.  Variables starting with the letters I thru N were implicit integers in FORTRAN, and were therefore used as loop counters by default. /ravi

            My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

            1 Reply Last reply
            0
            • M Mycroft Holmes

              Looking at Marc's early work on the commodore 64 raised the following question? Why do we seem to use i and j for loop variables? Where did it come from I wonder. And no I have not tried to google it!

              Never underestimate the power of human stupidity RAH

              T Offline
              T Offline
              Tomaz Stih 0
              wrote on last edited by
              #6

              Mycroft Holmes wrote:

              Why do we seem to use i and j for loop variables?

              In the east we traditionally used n and m. And p and q for pointers. It wouldn't surprise me if it was just to be different from the decadent west.

              C 1 Reply Last reply
              0
              • M Mycroft Holmes

                Looking at Marc's early work on the commodore 64 raised the following question? Why do we seem to use i and j for loop variables? Where did it come from I wonder. And no I have not tried to google it!

                Never underestimate the power of human stupidity RAH

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #7

                To add to what the others said about FORTRAN default variable types, variable names were limited to 6 characters as well so short variable names were a good idea. It was a convention that "generic loop counters" were I, J, and K (no lower case in those days, either!) In addition, lines were limited to 80 characters of which the first 6 where for label numbers, used to target lines with GOTO and suchlike flow control; and the seventh was for a "Continuation character" which allowed you to use more than 72 characters in your code statement. Short names were a good idea in those days! :laugh:

                Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                N B 2 Replies Last reply
                0
                • D dan sh

                  Because there is a little bit of FORTRAN in all of us?

                  "It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[^]

                  M Offline
                  M Offline
                  Mycroft Holmes
                  wrote on last edited by
                  #8

                  And everyone who wrote the early tutorials were probably steeped in FORTRAN conventions.

                  Never underestimate the power of human stupidity RAH

                  D 1 Reply Last reply
                  0
                  • T Tomaz Stih 0

                    Mycroft Holmes wrote:

                    Why do we seem to use i and j for loop variables?

                    In the east we traditionally used n and m. And p and q for pointers. It wouldn't surprise me if it was just to be different from the decadent west.

                    C Offline
                    C Offline
                    cjb110
                    wrote on last edited by
                    #9

                    If you took the Fortran IJKLMN, are the letters in the same order when translated to eastern languages? That may explain why your typically using n/m.

                    1 Reply Last reply
                    0
                    • M Mycroft Holmes

                      Looking at Marc's early work on the commodore 64 raised the following question? Why do we seem to use i and j for loop variables? Where did it come from I wonder. And no I have not tried to google it!

                      Never underestimate the power of human stupidity RAH

                      V Offline
                      V Offline
                      V 0
                      wrote on last edited by
                      #10

                      It might have come from FORTRAN, but "i" was also used for short of "index". When using nested loops the next letter was the most obvious ("j", "k", ...) For me personally it makes perfect sense in some way. If you see a one letter variable in code, there is almost a 100% chance that it is a loop variable. Also a one letter loop variable in an array indication (some_array[i]) is easier readable than (some_array[index]). (though that is perhaps personal taste)

                      V.

                      (MQOTD rules and previous solutions)

                      OriginalGriffO D 2 Replies Last reply
                      0
                      • M Mycroft Holmes

                        And everyone who wrote the early tutorials were probably steeped in FORTRAN conventions.

                        Never underestimate the power of human stupidity RAH

                        D Offline
                        D Offline
                        den2k88
                        wrote on last edited by
                        #11

                        And the professors who taught us - or those who taught our professors - have a lot more FORTRAN than us so it's a cycle. Add the fact that i and j are short and as good as any single letter...

                        DURA LEX, SED LEX GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver When I was six, there were no ones and zeroes - only zeroes. And not all of them worked. -- Ravi Bhavnani

                        1 Reply Last reply
                        0
                        • V V 0

                          It might have come from FORTRAN, but "i" was also used for short of "index". When using nested loops the next letter was the most obvious ("j", "k", ...) For me personally it makes perfect sense in some way. If you see a one letter variable in code, there is almost a 100% chance that it is a loop variable. Also a one letter loop variable in an array indication (some_array[i]) is easier readable than (some_array[index]). (though that is perhaps personal taste)

                          V.

                          (MQOTD rules and previous solutions)

                          OriginalGriffO Offline
                          OriginalGriffO Offline
                          OriginalGriff
                          wrote on last edited by
                          #12

                          V. wrote:

                          If you see a one letter variable in code, there is almost a 100% chance that it is a loop variable.

                          Or you are in QA... :sigh:

                          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                          1 Reply Last reply
                          0
                          • V V 0

                            It might have come from FORTRAN, but "i" was also used for short of "index". When using nested loops the next letter was the most obvious ("j", "k", ...) For me personally it makes perfect sense in some way. If you see a one letter variable in code, there is almost a 100% chance that it is a loop variable. Also a one letter loop variable in an array indication (some_array[i]) is easier readable than (some_array[index]). (though that is perhaps personal taste)

                            V.

                            (MQOTD rules and previous solutions)

                            D Offline
                            D Offline
                            den2k88
                            wrote on last edited by
                            #13

                            V. wrote:

                            loop variable in an array indication (some_array[i]) is easier readable than (some_array[index]). (though that is perhaps personal taste)

                            It depends if that variable has other meaning / is meant to be stored but yes, I concur.

                            DURA LEX, SED LEX GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver When I was six, there were no ones and zeroes - only zeroes. And not all of them worked. -- Ravi Bhavnani

                            1 Reply Last reply
                            0
                            • OriginalGriffO OriginalGriff

                              To add to what the others said about FORTRAN default variable types, variable names were limited to 6 characters as well so short variable names were a good idea. It was a convention that "generic loop counters" were I, J, and K (no lower case in those days, either!) In addition, lines were limited to 80 characters of which the first 6 where for label numbers, used to target lines with GOTO and suchlike flow control; and the seventh was for a "Continuation character" which allowed you to use more than 72 characters in your code statement. Short names were a good idea in those days! :laugh:

                              Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                              N Offline
                              N Offline
                              Nagy Vilmos
                              wrote on last edited by
                              #14

                              Short names still are a good idea. As a general rule, I'll use initials for temporary variables in loops etc and as the scope gets greater increase the size and detail of the name.

                              veni bibi saltavi

                              1 Reply Last reply
                              0
                              • M Mycroft Holmes

                                Looking at Marc's early work on the commodore 64 raised the following question? Why do we seem to use i and j for loop variables? Where did it come from I wonder. And no I have not tried to google it!

                                Never underestimate the power of human stupidity RAH

                                P Offline
                                P Offline
                                Peter_in_2780
                                wrote on last edited by
                                #15

                                I was initially going to nod to the FORTRAN crowd, then I thought further back, to linear algebra. Indices in vectors and matrices were traditionally i, j, ... My 2cents. Cheers, Peter

                                Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

                                F S 2 Replies Last reply
                                0
                                • OriginalGriffO OriginalGriff

                                  To add to what the others said about FORTRAN default variable types, variable names were limited to 6 characters as well so short variable names were a good idea. It was a convention that "generic loop counters" were I, J, and K (no lower case in those days, either!) In addition, lines were limited to 80 characters of which the first 6 where for label numbers, used to target lines with GOTO and suchlike flow control; and the seventh was for a "Continuation character" which allowed you to use more than 72 characters in your code statement. Short names were a good idea in those days! :laugh:

                                  Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                                  B Offline
                                  B Offline
                                  Besinger
                                  wrote on last edited by
                                  #16

                                  Especially when you had to put them on punch cards!

                                  1 Reply Last reply
                                  0
                                  • M Mycroft Holmes

                                    Looking at Marc's early work on the commodore 64 raised the following question? Why do we seem to use i and j for loop variables? Where did it come from I wonder. And no I have not tried to google it!

                                    Never underestimate the power of human stupidity RAH

                                    L Offline
                                    L Offline
                                    Lost User
                                    wrote on last edited by
                                    #17

                                    Here maybe although they use n and k a lot[^]

                                    1 Reply Last reply
                                    0
                                    • P Peter_in_2780

                                      I was initially going to nod to the FORTRAN crowd, then I thought further back, to linear algebra. Indices in vectors and matrices were traditionally i, j, ... My 2cents. Cheers, Peter

                                      Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

                                      F Offline
                                      F Offline
                                      Forogar
                                      wrote on last edited by
                                      #18

                                      The designers of FORTRAN used I,J,...etc. because FORTRAN was designed for FORmula TRANslation and a lot of the language development came from having to process this linear algebra. So when the Integer variables were defined it was natural to use I and J, etc. So which came first the chicken or the egg?

                                      - I would love to change the world, but they won’t give me the source code.

                                      P 1 Reply Last reply
                                      0
                                      • F Forogar

                                        The designers of FORTRAN used I,J,...etc. because FORTRAN was designed for FORmula TRANslation and a lot of the language development came from having to process this linear algebra. So when the Integer variables were defined it was natural to use I and J, etc. So which came first the chicken or the egg?

                                        - I would love to change the world, but they won’t give me the source code.

                                        P Offline
                                        P Offline
                                        Peter_in_2780
                                        wrote on last edited by
                                        #19

                                        There is no chicken/egg debate. I'm saying FORTRAN followed the linear algebra usage.

                                        Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

                                        S 1 Reply Last reply
                                        0
                                        • P Peter_in_2780

                                          I was initially going to nod to the FORTRAN crowd, then I thought further back, to linear algebra. Indices in vectors and matrices were traditionally i, j, ... My 2cents. Cheers, Peter

                                          Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

                                          S Offline
                                          S Offline
                                          Stefan_Lang
                                          wrote on last edited by
                                          #20

                                          For matrices I typically prefer row and column. That's still reasonably short, and can help a lot in the readability of some of the matrix operations. (talking of linear algebra matrices here, but you might apply the same reasoning to database tables, resulting in index names like record and field)

                                          GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups