How do `DO` loops work in Fortran 66?

前端 未结 3 1086
梦谈多话
梦谈多话 2021-01-03 06:41

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.

相关标签:
3条回答
  • 2021-01-03 07:01

    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.

    0 讨论(0)
  • 2021-01-03 07:07

    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
    
          stop
          end
    

    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

    0 讨论(0)
  • 2021-01-03 07:10

    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.

    0 讨论(0)
提交回复
热议问题