Re: New style DO syntax?
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 25 Apr 2006 17:23:26 +0000 (UTC)
Gordon Sande <g.sande@xxxxxxxxxxxxxxxx> wrote:
On 2006-04-25 12:51:46 -0300, *** Hendrickson <***.hendrickson@xxxxxxx> said:(snip about improving DO loops)
I find that I follow pointer chains often enough that I have fixed
idioms for doing it. I also find that I want to lower the upper limit
or redo the current iterate again, or do both of these. So generalized
termination test, generalized successor with ability to modify index or
parts of expressions in the statements.
Algol 60 had a truly omnibus for statement that was readable because it
had fully spelt out keywords. So much so that the trivial I=1,10 was
verbose.
PL/I uses nice short keywords DO I=1 TO 100 BY 2;
To mark the revised iteration form the keyword DO should not be used.
It should be left alone as the no fuss simple easy to optimize common
case.
The C for statement if a reasonable balance even if the choice of
punctuation leaves a lot to be desired. The many possible clauses of
Algol 60 would be too much of a culture clash with Fortran so I would
not expect somethinng that generalized.
General form of
FOR initialize THEN successor WHILE ( temination )
You could also allow exchanging the order of THEN and WHILE,
or even multiple THEN and WHILE groups. Maybe also an UNTIL
where the test is done at the end of the loop.
with a toy nonsense illustration
FOR i = 1 THEN i = i + 1 WHILE ( whatever )
instead of C's for ( i = 1; whatever; i = i + 1 )
Note for non-C users, the three parts of the for group are
general, such that different variables or more general expresions
can be used. The C comma operator allows multiple loop variables
to be initialized or modified in the loop. The test can be any
expression such that the loop continues as long as it is non-zero
(true in C logic).
for(i=1, j=10; i<j; i++, j--)
for(i=1; j<10; k *= 2)
The comma operator evaluates the left operand then the right
operand, and returns the value of the right operand.
For linked list processing:
for(p=start; p ; p=p->next)
-- glen
.
- References:
- New style DO syntax?
- From: Joe Krahn
- Re: New style DO syntax?
- From: *** Hendrickson
- Re: New style DO syntax?
- From: Gordon Sande
- New style DO syntax?
- Prev by Date: Re: New style DO syntax?
- Next by Date: Re: New style DO syntax?
- Previous by thread: Re: New style DO syntax?
- Next by thread: Re: New style DO syntax?
- Index(es):