Loop iterator - example.txt

Rick C. Hodgin Rick_member at pathlink.com
Fri Apr 28 13:31:07 PDT 2006


Here's an idea:

There should be a way in D to allow the reconsideration of a for..loop test
clause without executing the increment clause.

Using the terminology:
for (initialize-clause; conditional-clause; increment-clause)

Example:
int i;
for (i=0; i<10; i++)
{
if (string.substr(i,1) == something)
{
i += some_other_function();
retry;
}
else if (string.substr(i,1) == something_else)
{
i += some_other_function2();
retry;
}
// Otherwise, simply execute the "i++" and re-test
}

I propose the name "retry" for the "retest without increment-clause" command, to
be used in a manner similar syntax-wise to the way "break" is used today.
"Retry" would simply bypass the increment-clause and proceed straight to the
conditional-clause code section, thereby allowing subsequent passes through the
for loop without the requisite and occasionally unnecessary auto-incrementation.

It would just be a way to give for loops a little more natural utility without
having to do some rather obtuse programming techniques, such as using goto's or
enclosing the code in a while or do loop, etc.

- Rick C. Hodgin


begin 0644 example.txt
M:6YT(&D[#0IF;W(@*&D],#L@:3PQ,#L@:2LK*0T*>PT*("`@(&EF("AS=')I
M;F<N<W5B<W1R*&DL,2D@/3T@<V]M971H:6YG*0T*("`@('L-"B`@("`@("`@
M:2`K/2!S;VUE7V]T:&5R7V9U;F-T:6]N*"D[#0H@("`@("`@(')E=')Y.PT*
M("`@('T-"B`@("!E;'-E(&EF("AS=')I;F<N<W5B<W1R*&DL,2D@/3T@<V]M
M971H:6YG7V5L<V4I#0H@("`@>PT*("`@("`@("!I("L]('-O;65?;W1H97)?
M9G5N8W1I;VXR*"D[#0H@("`@("`@(')E=')Y.PT*("`@('T-"B`@("`O+R!/
M=&AE<G=I<V4L('-I;7!L>2!E>&5C=71E('1H92`B:2LK(B!A;F0@<F4M=&5S
&=`T*?0T*
`
end



More information about the Digitalmars-d mailing list