Loop iterator - example.txt

Walter Bright newshound at digitalmars.com
Sat Apr 29 13:27:53 PDT 2006


Rick C. Hodgin wrote:
> 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 know goto's are evil, but I tend to write such as:

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



More information about the Digitalmars-d mailing list