program exitloop

  implicit none
  integer :: i
  real :: x

  i = 0
  do
    i = i+1
    if (i >= 5 .and. i <= 9) cycle
    if (i > 10) exit
    write(*,*) "i is", i
  enddo
  write(*,*) "Loop finished. i =", i

  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
    write(*,*) "i is", i
  enddo
  write(*,*) "Loop finished. i =", i

end program exitloop
