Difference between revisions 2492468 and 2492493 on enwikibooks

[[File:CCBYSA yellow.png]]

=Preface=
The goal of this Fortran tutorial is to give a quick introduction to the most common features of the Fortran 77 programming language. A companion tutorial introduces the key enhancements found in Fortran 90. It is not a complete reference! Many details have been omitted. The presentation focuses on scientific computations, mainly linear algebra. The outline of this tutorial was inspired by the book "Handbook for Matrix Computations" by T.F. Coleman and C. Van (contracted; show full)or alternatively,

      do while (logical expr) 
         statements
      enddo
The program will alternate testing the condition and executing the statements in the body as long as the condition in the while statement is true. Even though this syntax is accepted by many compilers, it is not ANSI Fortran 77. The correct way is to use if and goto:


<code>
 label if (logical expr) then
         statements
         goto label
        endif</code> 
Here is an example that calculates and prints all the powers of two that are less than or equal to 100:

     integer n

     n = 1
  10 if (n .le. 100) then
        write (*,*) n
        n = 2*n
        goto 10
     endif


==until-loops==

If the termination criterion is at the end instead of the beginning, it is often called an until-loop. The pseudocode looks like this:

      do
         statements
      until (logical expr)
Again, this should be implemented in Fortran 77 by using if and goto:
(contracted; show full) Sarah T. Whitlock and Paul H. Hargrove for use in the Fortran courses which have been offered under different course numbers each subsequent year. The original source of the material is here http://www.stanford.edu/class/me200c/tutorial_77/ Stanford university has re-released the material under a creative commons 3.0 attribution license. The tutorial was transferred to mediawiki format by Houraa Daher.

{{Subjects|Computer programming|University level mathematics books}}
{{alphabetical|F}}
{{status|100%}}