Sign up ×

I'm reading an old book I found in a second-hand book shop (again). This one is called "Fortran techniques - with special reference to non-numerical applications", by A. Colin Day, published by Cambridge University Press in 1972. It is, after all, very important to keep up with the latest in software development ;-)

This book claims to cover Fortran-66 (X3.9-1966), aka Fortran-IV, with a minor departure from that standard for DATA statements which isn't relevant here.

The trouble is, the book seems to leave a lot to guesswork, and my guesses are pretty uncertain WRT the DO loop. This is in chapter 1, so not a very good sign.

Here is one example...

    DO 15 I = 1, 87
    J = I - 44

In the DO line, 1 and 87 seem to represent the inclusive range for the loop - I takes values 1 to 87 inclusive, so J takes values -43 to +43 inclusive. However, what does the 15 represent?

Another example is...

    N = 1
    DO 33 I = 1, 10
33  N = N + N

In this case, 33 looks like a label or line number - presumably the last line executed before the loop repeats (or exits). But 33 is an odd number to choose just as an arbitrary label.

EDIT That was a mistake - see the answer by duffymo - How do `DO` loops work in Fortran 66?

And the very next example after that is...

    DO 33 I = 1, 10
    N = 2 ** (I-1)

Again using the same 33, but without any line being explicitly labelled with it.

Am I being confused because these are short snippets taken out of context? What does the n in DO n ... represent?

share|improve this question
@eriktous - I looked for tutorials, but none covered Fortran IV or 66 - 77 seemed to be the oldest version. I didn't think to look for the standard - I imagine there's a copyright issue, even for ancient versions of languages. I may be better off learning 77 anyway - it's not that serious, and there's no particular reason for learning one version over another except this one book, which seems more like a "snippets" book than a language tutorial or reference anyway. – Steve314 Jul 30 '11 at 20:01
The F66 and F77 standards are openly available on the NAG (Numerical Algorithms Group) ftp server, which serves as a host for the working documents of the standard committee ( You can find draft versions of the later standards there also. The final draft of a particular standard is practically the same as the official standard. The gfortran wiki has a nice collection of links to the various documents ( Unless you have to work with legacy code, there is really no good reason not to learn modern Fortran. – eriktous Aug 1 '11 at 22:44
@eriktous - Thanks - those links will be useful. My only reason to learn Fortran at all is to better understand the history of programming language design, though, and learning more recent versions wouldn't help with that. – Steve314 Aug 2 '11 at 0:28

3 Answers 3

up vote 3 down vote accepted

Here is a complete program that should answer some of your questions. One can easily test this history question ... FORTRAN IV is still supported by numerous compilers, though portions of FORTRAN IV are either officially obsolescent or, in my opinion, should be obsolete. I compiled and checked this program with both g77 (which is close to obsolete since it is long unsupported) and gfortran.

Here is a sample program:

      implicit none

      integer i
      real q

      q = 1.0
      do i=1, 10
         q = q * 1.5
      end do
      write (6, *) "modern loop: q =", q

      q = 1.0
      do 100 i=1, 10
         q = q * 1.5
  100 continue
      write (6, *) "loop with continue: q =", q

      q = 1.0
      do 200 i=1, 10
  200 q = q * 1.5
      write (6, *) "loop without continue: q =", q


And how to compile it with gfortran: gfortran -ffixed-form -ffixed-line-length-none -std=gnu test_loops.for -o test_loops.exe

Re your question: if you terminate the loop with a labeled line that is an executable code, is that line part of the loop? The output of the program clearly shows that the labeled line IS part of the loop. Here is the output of gfortran:

modern loop: q = 57.665039
loop with continue: q = 57.665039
loop without continue: q = 57.665039

share|improve this answer

The line number tells the code where to go when the loop is complete.

Yes, the numbers are odd, arbitrary, and meaningless. It's part of what made FORTRAN hard to read and understand.

share|improve this answer
But... how does Fortran know which lines to execute as part of the loop? Is it just the next line? Or the lines up to that labelled line? And for that second example, with the 33 N = N + N, the book strongly implies that line is executed within the loop - it's introduced with "If a loop is needed in which N assumes values 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, i.e. doubling in value each time, then the solution could be:". – Steve314 Jul 29 '11 at 14:11
A Fortran 77 tutorial I found - - suggests that the end of each loop should be marked with continue. Does falling off the end of a program cause an implicit continue for any outstanding DO loops? Did the author just miss out the continue to confuse people? – Steve314 Jul 29 '11 at 14:33
No, continue was a later addition to the language. It was originally all line label numbers. – duffymo Jul 29 '11 at 14:48
Well, I'm still confused - not clear how Fortran knows which lines to execute within the loop, and whether that includes the labelled line or not - but I don't think it's my fault. – Steve314 Jul 29 '11 at 14:52
All the lines between the DO (inclusive) and the continue/labeled line (exclusive). The labeled line is just the place where you land when you exit. – duffymo Jul 29 '11 at 14:55

The number 15 known as a "Label" it was decided by the programmer. Depending on organisational standards these numbers were controlled and followed specific rules. Although some programmers didn't keep to standards and their code was a mess; Comments and line indentations were also part of standards followed by most.

share|improve this answer

Your Answer


