For Programmers: Free Programming Magazines  


Home > Archive > Fortran > November 2004 > Exit in Fortran 90/95









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Exit in Fortran 90/95
victor

2004-11-15, 3:59 pm

Hi Experts,

How we can exit from inside a do-loop to outside the function?
I don't want the STOP which will go outside the whole program.

program myProgram
....
contains
logical function myFunction()
....
do i=1,100
....
EXIT this function
....
end do
end function myFunction
end program myProgram

Thank you in advance.
Jugoslav Dujic

2004-11-15, 3:59 pm

victor wrote:
| Hi Experts,
|
| How we can exit from inside a do-loop to outside the function?
| I don't want the STOP which will go outside the whole program.
|
| program myProgram
| ...
| contains
| logical function myFunction()
| ...
| do i=1,100
| ...
| EXIT this function
| ...
| end do
| end function myFunction
| end program myProgram
|
| Thank you in advance.

RETURN.

--
Jugoslav
___________
www.geocities.com/jdujic

Please reply to the newsgroup.
You can find my real e-mail on my home page above.

Michael Metcalf

2004-11-15, 3:59 pm


"Jugoslav Dujic" <jdujic@yahoo.com> wrote in message
news:2vs4dsF2p32dfU1@uni-berlin.de...
> victor wrote:
> | Hi Experts,
> |
> | How we can exit from inside a do-loop to outside the function?
> | I don't want the STOP which will go outside the whole program.
> |
> | program myProgram
> | ...
> | contains
> | logical function myFunction()
> | ...
> | do i=1,100
> | ...
> | EXIT this function
> | ...
> | end do
> | end function myFunction
> | end program myProgram
> |
> | Thank you in advance.
>
> RETURN.
>

In general. But for the code above, also just EXIT would do.

Regards,

Mike Metcalf


victor

2004-11-15, 8:56 pm

Thanks a lot for the answers!
It looks we can append something(number?) after 'return' or 'exit'.
Can you tell me how to use that?

"Michael Metcalf" <michael.metcalf@t-online.de> wrote in message news:<cnamp3$afg$1@ngspool-d02.news.aol.com>...
> "Jugoslav Dujic" <jdujic@yahoo.com> wrote in message
> news:2vs4dsF2p32dfU1@uni-berlin.de...
> In general. But for the code above, also just EXIT would do.
>
> Regards,
>
> Mike Metcalf

Ian Bush

2004-11-16, 8:56 am

victor wrote:

> Thanks a lot for the answers!
> It looks we can append something(number?) after 'return' or 'exit'.
> Can you tell me how to use that?
>


After exit ( or cycle ) you can put a do construct name. It works
something like this:

Loop1: Do i = 1, 10
Do j = 1, 10
Do k = 1, 10
........
! WHOOPS, an error has come up
If( something ) Then
error_code = 1
Exit Loop1
End If
........
End Do
End Do
End Do

A plain exit would just exit the loop it is in ( the k loop )
done like this it exists the loop with the given name, the i loop
in this case.

It is true you can also put something after the return statement.
You really, really, really, really, really, really, really, really,
really, really, do not want to know about that !

Ian

jan van oosterwijk

2004-11-16, 3:57 pm

victor@in-box.net (victor) wrote in message news:<aec1ceb.0411150834.1058d598@posting.google.com>...
> Hi Experts,
>
> How we can exit from inside a do-loop to outside the function?
> I don't want the STOP which will go outside the whole program.


The STOP statement may take a number or a string, but
with EXIT you can add the block name like this :

program myProgram
...
stop "END Program"
contains
logical function myFunction()
...
This_function: do i=1,100
...
if( ... ) EXIT this_function
...
end do this_function
end function myFunction
end program myProgram


[JvO]
Richard E Maine

2004-11-16, 3:57 pm

Ian Bush <I.J.Bush@nospam.dl.ac.uk> writes:

> After exit ( or cycle ) you can put a do construct name.


Indeed my personal style guideline is to never use EXIT without
the construct name. I find the unnamed exit too potentially confusing
to the reader. It raises the natural question of "exit what?"
I know the answer, but casual readers might not. For one example,
it would be easy to misread as a synonym for return. With the
name, even a fairly casual reader ought to get the idea that it
is exiting something with that name.

If the language ever adds the feature to allow exiting from other
kinds of constructs (as has been proposed), then the unnamed
exit will be even more confusing. In fact, that is at least a minor
bar to the introduction of such a feature - the rules have to be
written carefully to avoid breaking existing code. And, alas, if
they have to be written carefully, that also means they have to be
read carefully. The prototypical (and quite common - so it can't
be ignored) example of this is an unnamed EXIT that is in an IF block
in a DO loop (which, of course, is in some procedure).

> It is true you can also put something after the return statement.
> You really, really, really, really, really, really, really, really,
> really, really, do not want to know about that !


I don't want to know about it either. But it is too late for me. :-)

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
Jim Giles

2004-11-16, 3:57 pm

Ian Bush <I.J.Bush@nospam.dl.ac.uk> wrote in message news:<cncjs5$ekh$1@mserv2.dl.ac.uk>...
....
> It is true you can also put something after the return statement.
> You really, really, really, really, really, really, really, really,
> really, really, do not want to know about that !


Well, actually, he probably may. But not until he's a little
more experienced. Alternate return is still the only feature
resembling part of an exception handling mechanism that Fortran
has. There is still no adequate replacement for it. The suggested
alternative in annex B of the standard rather succinctly expresses
whthat suggested alternative is worse that the alternate return:
it replaces one line of code whose intent is fairly clear with
several whose intent is not at all clear.

--
J. Giles

"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com