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.
  • 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
                            • P Peter_in_2780

                              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 Offline
                              S Offline
                              Stefan_Lang
                              wrote on last edited by
                              #21

                              I concur. Tensor algebra is much older than FORTRAN, and they always used i, j, k, l for indices, continuing with m, n, and (rarely) more when needed. Mathematicians are notoriously lazy, so they never waste more than one letter for an index variable. ;)

                              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