There is a program to go with today's lecture called nested.f - to get it from my directory, type the following (and then compile with f90)
cp ~gheard/nested.f .
f90 -o nested nested.f
NESTED DO LOOPS
Just like the nested IF statements, there can be a DO loop within another DO loop. The most obvious use of this is in matrix manipulation. The program nested.f is a new version of the crazy text program which uses a nested loop
C For FORTRAN course - takes a number of lines of input and
C strings them together in strange ways
PRINT *, " A version of the crazy text program using nested loops"
PRINT *, " Enter a 6-character sequence"
READ *, INCHR
DO 100 N=1, 6
DO 200 M=1,N
OUTCHR = " "
OUTCHR(M:N) = INCHR(M:N)
PRINT *, OUTCHR
The only rule with nested loops is the same as for nested IF statements - the inner loop must end before the outer loop. In the program above, if lines 200 and 100 were switched, then the program would not compile
There is no limit to the number of loops nested within each other (tensor operations require three loops)
Try changing something about the nested loops in this program
NOTES ON THE MIDTERM
The midterm will be held next Friday, in the lecture room. Dr. Manns, who used to teach this course some years ago, has kindly given me a folder of her old midterms. I have copies of two of them in a folder which is available to borrow and copy for yourself.
I would also recommend doing the exercises at the end of each section of the book, starting with Chapter 2, with the exception of exercises 3.6 (since we are not that interested in complex logic statements)
Since Dr. Manns' midterms are probably a little different in style to mine, I will do my own sample midterm and put it on the web for Monday.