Loop iterator - example.txt

Rick C. Hodgin Rick_member at pathlink.com
Sun Apr 30 20:30:35 PDT 2006


In article <e30i88$1q4n$1 at digitaldaemon.com>, Walter Bright says...
>
>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
>}

The problem here is the test condition is not being executed.  In theory, "i +=
some_other_function()" 
could increment i beyond the value desired in the for loop conditional-clause.
The Lretry would not 
officially retry the test condition and could, therefore, potentially execute on
values of i that are 
undesired by being outside the scope of the for loop, introducing a trait that a
well-written program 
should not include.

- Rick C. Hodgin





More information about the Digitalmars-d mailing list