Fortran 90 and later strongly recommend not to use goto
statement.
However, I still feel forced to use it in either of the two cases:
Case 1 -- Instruct to re-enter the input value, e.g.
program reenter
10 print*,'Enter a positive number'
read*, n
if (n < 0) then
print*,'The number is negative!'
goto 10
end if
print*,'Root of the given number',sqrt(float(n))
stop
end program reenter
Case 2 -- To comment a large continuous part of a program (an equivalent to /* ... */
in C).
Eg.
print*,'This is to printed'
goto 50
print*,'Blah'
print*,'Blah Blah'
print*,'Blah Blah Blah'
50 continue
print*,'Blahs not printed'
How can I get rid of using goto
statement and use some alternatives in the above two cases in Fortran 90?