Re: New style DO syntax?
- From: "James Giles" <jamesgiles@xxxxxxxxxxxxxxxx>
- Date: Tue, 25 Apr 2006 22:09:23 GMT
Gordon Sande wrote:
....
The structure of
i = 0
do while(termination)
i = i + 1
...
end do
needed to have the first iteration have i of 1 to be rather
confusing. Logically correct but awkward to read.
I don't find that all that awkward, but I still prefer the
present Do 1=1,N. The above pattern is not so bad
when applied to other things. Like, say, list traversal:
next => head
Do while (associated(next))
current => next
next => current%link
body of loop
End do
All the looping conditions are at the start of the loop.
There's a variable NEXT that is, strictly speaking, not
really necessary. A good compiler should eliminate it
as part of optimization. The alternatives I believe to
be less legible:
current => head
Do while (associated(current))
body of loop
current => current%link
End do
Someone looking at the start of the loop won't necessarily
see that the loop is a simple traversal. Gets rid of NEXT
though. A mixed blessing since NEXT might be convenient
within the body of the loop anyway.
Or:
FOR current => head &
THEN current => current%link &
WHILE associated(current)
body of loop
End for
This is the form previously suggested in this thread. (Placing
it all on one line is even less legible.) I suppose one can
get used to anything. I'd probably continue to use the first
version I show above.
--
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
.
- References:
- New style DO syntax?
- From: Joe Krahn
- Re: New style DO syntax?
- From: *** Hendrickson
- Re: New style DO syntax?
- From: Gordon Sande
- Re: New style DO syntax?
- From: James Giles
- Re: New style DO syntax?
- From: Gordon Sande
- New style DO syntax?
- Prev by Date: Re: Compiling in 32 vs 64 platform problem
- Next by Date: Re: Compiling in 32 vs 64 platform problem
- Previous by thread: Re: "GOTO considered harmful" considered harmful. Re: New style DO syntax?
- Next by thread: Re: New style DO syntax?
- Index(es):