Re: New style DO syntax?



Gordon Sande <g.sande@xxxxxxxxxxxxxxxx> wrote:

At one extreme there is the "everything is a goto" school and at
the other is "57 flavours of iterations". Neither makes for a
good programming language design. The existing Fortran DO is
pretty good at doing a very common thing well. But its "any
colour as long as its black" style is rather restrictive.
The camels nose was FORALL so folks keep suggesting decorations
on DO. The question is not what Universal Iteration Construct
one could design but rather what is in keeping with the Fortran
style and is a worthwhile extension/addition.

Note the considerable extension to DO between Fortran 66 and 77.

Are you suggesting allowing a whole block of code as the
"initialize" and "successor" parts? If not, what happens
when the loop requires more initialization or successoring (?)
than one statement can handle?
(snip)

I find the C notion of multiple statements (separated by commas)
in the various parts to be overly prone to confusion upon reading.
When the loop syntax holds everything then it seems a case of not
being clear on the concept of a concise looping structure. So no, I
would not want to suggest that and you are quite right to question
any such notion.

One should code in the way that makes it most readable. If there
are multiple loop variables, especially if they are equal significance,
it doesn't make sense to give one special status.

There are many constructs in C that can make code harder to read,
so their use is discouraged. (Except for entries to the IOCCC,
see www.ioccc.org for more information.) If multiple initializations
or successors are needed, and it is more readable, they should all
be together. The use of the continue statement has some effect
on this.

Note, though, that C doesn't allow multiple statements or even
multiple expressions. It allows one expression (no statements),
but the comma operator makes it look like more than one. Comma
has the lowest precedence even lower than the assignment operators.

x=(1,2,3);

is a legal assignment which will assign 3 to x.

(1,2,3);

is a legal expression which does nothing at all.

-- glen


.