PROGRAM simpleloop

  IMPLICIT NONE
  INTEGER :: i, j, icnt
  REAL :: x

!-- 1) a simple indexed loop
  DO i = 1,10
    x = REAL(i*2)
    !i = i+2               ! attempt to change the loop index
    WRITE(*,*) "i = ",i,"x = ",x
  ENDDO
  
  WRITE(*,*) 'hit ENTER to continue'
  READ(*,*)  ! trick to get the program to pause
  
!-- 2) a simple indexed loop with a step
  DO i = 1,10,2
    x = real(i*2)
    WRITE(*,*) "i = ",i,"x = ",x
  ENDDO
  
  WRITE(*,*) 'hit ENTER to continue'
  READ(*,*)  ! trick to get the program to pause
  
!-- 3) a simple indexed loop that counts down
  DO i = 10,1,-1
    x = real(i*2)
    WRITE(*,*) "i = ",i,"x = ",x
  ENDDO
  
  WRITE(*,*) 'hit ENTER to continue'
  READ(*,*)  ! trick to get the program to pause
  
!-- 4) a simple indexed loop with a negative 2 step
  DO i = 10,1,-2
    x = real(i*2)
    WRITE(*,*) "i = ",i,"x = ",x
  ENDDO
  
  WRITE(*,*) 'hit ENTER to continue'
  READ(*,*)  ! trick to get the program to pause
  
!-- 5) nested loops
  icnt = 0
  DO i = 1,10
    DO j = 1,5
      x = i*j
      IF (x .eq. 40) icnt = icnt+1
    ENDDO
  ENDDO
  WRITE(*,*) 'icnt = ',icnt

END PROGRAM simpleloop
