How do `DO` loops work in Fortran 66?

前端 未结 3 1083
梦谈多话
梦谈多话 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: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

提交回复
热议问题