david,
So what you are saying is if I test i, and it lies in between the loop limits (inclusive) then it was a forced EXIT, but if i is something else, the loop was run to completion with no forced exit?
Eddie
Welcome to our forums
david,
So what you are saying is if I test i, and it lies in between the loop limits (inclusive) then it was a forced EXIT, but if i is something else, the loop was run to completion with no forced exit?
Eddie
Eddie,
With F90, the DO index is defined on exit. I use this feature extensively, to test the type of exit. Searching a list for an item is a typical use.
DO I = 1, num_known
if ( possible == list(I) ) exit
END DO
if ( I > num_known ) then ! add new item
list(I) = possible
num_known = I
end if
Quoted from LitusSaxonicum david,
So what you are saying is if I test i, and it lies in between the loop limits (inclusive) then it was a forced EXIT, but if i is something else, the loop was run to completion with no forced exit?
Eddie
Almost. If i is something else, the loop was run to completion or was not entered at all.
Have a look at John's search/append new item example above this for a typical use case. His code will still work properly when num_known = 0.
Well, this is all very interesting, and I’m happy to be educated (sincerely), but it comprises what I call ‘Cotton-Eyed Joe’ programming style:
Where did you come from, how do I know? Where did you come from, Cotton-Eyed Joe?*
Whereas my style is to know without needing to ask, on the grounds that there was only one route in, decided in advance, and signposted in traditional redneck style by a bunch of GO TOs.
A great example of Cotton-Eyed Joe programming is in a Clearwin+ %gr callback, where the first thing you have to ask is: “Where did you come from?” via -
COTTON_EYED_JOE_string = clearwin_string@ ('CALLBACK_REASON')
It’s a paradigm that I don’t like or use much – only when I have to (like there).
If it hadn't been for Cotton-Eyed Joe It'd been working a long time ago.**
The alternate paradigm is exemplified by a set of callback functions for buttons on a form: you know within each callback function where it came from – although you can Cotton-Eyed Joe it by testing the WINIO@ return code instead.
Eddie
*Yes, I know I changed the words. I don’t need to ask where he’ll go. It’s there in the GO TO! **I changed these too, on the grounds that the originals didn’t apply. 50 years and 4 days ago, if you must ask.