Reputation: 23
I am working on a piece of legacy F77 code and trying to convert it to equivalent F90 code. I ran into these lines below and could some one advise if my conversion is correct?
Fortran 77 code:
Subroutine area(x,y,z,d)
do 15 j=1,10
if (a.gt.b) go to 20
15 CONTINUE
20 Statement 1
Statement 2
Statement 3
end subroutine
I tried to convert it to F90 and came up as below:
Subroutine area(x,y,z,d)
dloop: do j=1,10
if (a>b) then
statement 1
statement 2
statement 3
else
write(*,*) 'Exiting dloop'
exit dloop
end if
end do dloop
end subroutine
Could anyone advise if this methodology is correct? In my results, I am not getting the results that I expect. So there could potentially be a problem with my logic.
Upvotes: 2
Views: 4493
Reputation: 18098
You got the translation slightly wrong... The first step is to rebuild the do
loop, which loops at 15
:
Subroutine area(x,y,z,d)
do j=1,10
if (a.gt.b) go to 20
enddo
20 Statement 1
Statement 2
Statement 3
end subroutine
Now you can see that the goto
results in "jumping out of the loop". In this particular example, this equivalent to an exit
, and the code can be written as
Subroutine area(x,y,z,d)
do j=1,10
if (a.gt.b) exit
enddo
Statement 1
Statement 2
Statement 3
end subroutine
Upvotes: 6