Proposal of a general do-while loop

Charles D Hixson charleshixsn at earthlink.net
Sat Jul 21 07:43:27 PDT 2007


downs wrote:

> void doWhile(void delegate() pre, lazy bool cond, void delegate() post) {
>   while (true) {
>     pre;
>     if (!cond()) break;
>     post;
>   }
> }
> 
> // listing 4, modified
> size_t pos=0;
> doWhile ({
>   pos=text.find(pattern, pos);
> }, pos!=string::npos, {
>   writefln("Pattern found at ", pos);
>   ++pos;
> });
> 
> Not tested, but should work.
> Have fun!

I suppose this, or something similar, would work...but UGH!! 
ugly.  I suppose that "De gustibus non disputandum est.", 
but... care for some okra pie with garlic ice cream?



More information about the Digitalmars-d mailing list