Re: New style DO syntax?



James Giles <jamesgiles@xxxxxxxxxxxxxxxx> wrote:
Gordon Sande wrote:
...
General form of

FOR initialize THEN successor WHILE ( temination )

with a toy nonsense illustration

FOR i = 1 THEN i = i + 1 WHILE ( whatever )

I've never liked putting the last thing a loop does at the
beginning of the loop. This "successor" code isn't invoked
at the beginning of the loop so it shouldn't be there. Even
within the statement, the WHILE condition is tested before
the successor code is invoked, why does it follow?

C doesn't require that you put it there. I have done loops
in C where the increment was at the end. That allows the
continue statement to start the iteration again without incrementing
the index variable, which is sometimes useful.

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? If you are expecting to allow
multiple statements, won't the programmer be tempted to
put the whole loop in the "successor" part (as is common
in the similar C construct)? In that case, what's the difference
between what you have and the following?

initialize
Do while(termination)
successor
End do

Well, since C doesn't have DO, it is nice to have for with
the initialization, test, and increment all in one statement,
as they are with DO. I never heard anyone complain that the
increment specification for DO was at the beginning of the loop.

Note that C only allows one expression for each position, but
the comma operator makes it look like more than one.
Note also that it is expression, and not statement, but that many
useful statements are actually expressions. (Any expression is
a legal statement in C, unlike Fortran.)

In a previous post I suggest allowing multiple THEN or WHILE
clauses in case multiple modifications or tests are needed.
(Though multiple tests can always be done with .AND. and .OR.)

-- glen




.