!================================== PROGRAM MORELOOPING !================================== ! This program demonstrates how ! simple loops work !================================== IMPLICIT NONE INTEGER :: i,j INTEGER, DIMENSION(10) :: myvector !- vector of length 10 INTEGER, DIMENSION(2,2) :: myarray !- 3x3 array !-- simple loop do i=1,10 myvector(i) = 1+i write(6,*) myvector(i) enddo !-- double loop (also called nested loop) !-- IMPORTANT: in fortran the first index runs fastest !-- in C/C++ it is the second one. do i=1,2 do j=1,2 myarray(j,i)=i+i*j write(6,*)j,i,myarray(j,i) enddo enddo !-- an example of using if statements (very artificial example) !-- and comparing values using .AND. and .OR. do i=1,10 do j=1,10 if (i > 2 .OR. j>2) then if(i > 2 .AND. j>2) then write(6,*)'both i and j are too large', j,i else if(i>2 .AND. j <= 2) then write(6,*)'i is too large', i else if(i <= 2 .AND. j > 2) then write(6,*)'j is too large', j endif else myarray(j,i)=i+i*j end if enddo enddo END PROGRAM MORELOOPING !==================================