PROGRAM EXITloop

  IMPLICIT NONE
  INTEGER :: i
  REAL :: x

  i = 0
  DO
    i = i+1
    IF (i >= 5 .and. i <= 9) CYCLE
    IF (i > 8) EXIT
    WRITE(*,*) "i is", i
  ENDDO
  WRITE(*,*) "Loop finished. i =", i

  WRITE(*,*) 'hit ENTER to continue'
  READ(*,*)  ! trick to get the program to pause

!-- you can also use EXIT and CYCLE on indexed loops
  do i = 1,10
    IF (i >= 5 .and. i <= 9) CYCLE
    IF (i > 10) EXIT  ! this is superfluous
    WRITE(*,*) "i is", i
  ENDDO
  WRITE(*,*) "Loop finished. i =", i

END PROGRAM EXITloop
