Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

[Fortran] Naming conventions for integers

  1. Jun 2, 2014 #1


    Staff: Mentor

    Long ago I learned Programming in FORTRAN. I got used to the convention that names starting with I,J,K,L,M,N were INTEGER while all other letters were REAL. I thought it was a convention of FORTRAN only. Since then, I came to realize that the same convention is widely used in science and math independent of computer programming. But I do not recall ever being explicitly taught any such convention.

    My question: what is the origin of this convention?

    I'm posting it here under math as a guess as to the right forum.

    P.s Wikipedia mentions this convention under "naming conventions (programming)", but it does not mention the origin.
  2. jcsd
  3. Jun 2, 2014 #2

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    In Fortran you don't necessarily have to declare variables. Just use them and voila! they exist. The default convention is that variables that start with I to N are integers. A variable whose initial character is A to H or O to Z means the variable is real by default.

    Note: IMPLICIT NONE turns off this default convention and forces a programmer to declare all variables. That's the recommended practice for new Fortran code. There's a lot of very old Fortran code still in use. Getting rid of the default convention would mean that a lot of this old code would have to be rewritten.
  4. Jun 2, 2014 #3


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    Why do you think such a convention was established for FORTRAN in the first place?

    The letters I-N have commonly been used in matrix notation and elsewhere to represent index variables, dummy variables, exponents, etc. Since FORTRAN was designed to be a FORmula TRANslator, making the letters I-N represent integer values, I think, was seen as a convenience to induce scientists and engineers to write programs in FORTRAN by making for less fussing with variable types when using common math formulas and procedures.
  5. Jun 2, 2014 #4
    I am not a mathematician or a historian and, yes, the first time I ever heard that variables representing integers start with the letters I though N was when I learned Fortran...whether I might have used those letter for integers before I had learned Fortran is possible, then again, I started to go to school quite a few years AFTER Fortran had been invented.

    Needless to say, such I-N convention was just a convenience for implicit variables.

    At the top of many old Fortran programs, there is an implicit statement at the top when they declare which initial variables are going to be used for what types of variables...I-N for integers, C for complex, everything else for reals or something like that.

    By the way, nobody has explicitly mentioned it, what I learned in Fortran is that the reason why the set of letters from I to N had been chosen to represent integers is because such (inclusive) I-N range can be represented just so using the first two letters of the word INteger itself.
  6. Jun 3, 2014 #5


    User Avatar
    Gold Member

    Today, the convention is to give variables meaningful names. The only exception to the rule is with indexes in loops.

    For example....
    Code (Text):

    area = height * width;
    instead of

    Code (Text):

    a = h * w;
  7. Jun 3, 2014 #6


    User Avatar
    Homework Helper

  8. Jun 3, 2014 #7
    Sure, but it does not say anything about the I-N convention, which is what the OP was wondering about.
  9. Jun 10, 2014 #8


    User Avatar
    Science Advisor
    Gold Member
    2017 Award

    I think the convention started with FORTRAN. Coming from a pure math background, I vaguely remember having a hard time with that convention at first. Before that, i and j meant the imaginary part of complex numbers to me. The m and n were more commonly used for integers. n was a natural number.
  10. Jun 10, 2014 #9


    User Avatar
    Homework Helper

    It predates Fortran. For example, summation or products series often use i, j, k for the iterating values and n (plus m and sometimes l) for the limiting values. i, j, k, ... are also used as an index / suffix when using a generic naming convention for terms in a polynomial, matrix, set, ... .
    Last edited: Jun 10, 2014
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - Fortran Naming conventions Date
[Fortran] Functions and naming conventions Sep 22, 2014
Fortran: opening variable file names Sep 27, 2012
Variable name in fortran Jul 22, 2011
Fortran: Passing loop names to subroutines Dec 15, 2009
Fortran - Output File names Jan 30, 2009