Loop iterator - example.txt

Hasan Aljudy hasan.aljudy at gmail.com
Sat Apr 29 22:13:18 PDT 2006


Very neat idea.
Several times I've run into situations where this construct would've 
been very helpful.

Gets my vote!

Rick C. Hodgin wrote:
> 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
> 
> 



More information about the Digitalmars-d mailing list