Removing goto statements in FORTRAN code

I have the code below and I want to remove the "go to" statements. Any idea how I can do it?

 if (iorder == 0) then

    tmincurrent = 1.0e11
    if(ireverse == 0 .or. istop /= 1) then
      do i = 1, 6
        if ((side(i) /= sidelimit(i)) .and. (tminside(i) < tmincurrent)) then
          tmincurrent = tminside(i)
          iside = i
        end if
      end do
    else
      do i = 1, 6
        if(side(i) /= sidestop(i) .and. tminside(i) < tmincurrent) then
          tmincurrent = tminside(i)
          iside = i
        end if
      end do
    end if

  else

    if ((ireverse == 0) .or. (istop /= 1)) then
      2120 ioc = ioc + 1
      if (ioc < 7) then
        iside = order(ioc)
        if (side(iside) /= sidelimit(iside)) go to 2130
      else
        ioc = 0
      end if
      go to 2120
    else
      2140 ioc = ioc + 1
      if (ioc < 7) then
        iside = order(ioc)
        if (side(iside) /= sidestop(iside)) go to 2130
      else
        ioc = 0
      end if
      go to 2140
    end if

  end if

2130  continue

All goto's like this can be refactored using a do/cycle/exit strategy. I wrote about this a bit at my Barrowes Consulting website.

In your case, the resulting code would be:

logical :: remg(3)=.true.
do
 if (remg(3)) then
  if (iorder == 0) then

   tmincurrent = 1.0e11
   if(ireverse == 0 .or. istop /= 1) then
    do i = 1, 6
     if ((side(i) /= sidelimit(i)) .and. (tminside(i) < tmincurrent)) then
      tmincurrent = tminside(i)
      iside = i
     endif
    enddo
   else
    do i = 1, 6
     if(side(i) /= sidestop(i) .and. tminside(i) < tmincurrent) then
      tmincurrent = tminside(i)
      iside = i
     endif
    enddo
   endif

  else

   if ((ireverse == 0) .or. (istop /= 1)) then
    do
2120 ioc = ioc + 1
     if (ioc < 7) then
      iside = order(ioc)
      if (side(iside) /= sidelimit(iside)) then
       remg(3)=.false.;exit
      endif
     else
      ioc = 0
     endif
     remg(1)=.false.;cycle
     exit
    enddo
    if (.not.(remg(3))) cycle
   else
    do
2140 ioc = ioc + 1
     if (ioc < 7) then
      iside = order(ioc)
      if (side(iside) /= sidestop(iside)) then
       remg(3)=.false.;exit
      endif
     else
      ioc = 0
     endif
     remg(2)=.false.;cycle
     exit
    enddo
    if (.not.(remg(3))) cycle
   endif

  endif

 endif
 remg(3)=.true.
2130 continue
 exit
enddo