Loop iterator - example.txt

Chris Nicholson-Sauls ibisbasenji at gmail.com
Wed May 3 14:15:01 PDT 2006


I'm all for the addition of 'retry' statement for all loops (while, for, foreach).  In 
fact, I think it would even be nifty in switch statements:

# switch (something) {
#   case foo:
#     doStuff();
#     break;
#
#   case bar:
#     doOtherStuff();
#     break;
#
#   default:
#     something = doAnotherThing();
#     retry;
# }

The 'restart' statement I'm not entirely convinced about, though.  For two reasons. 
Reason one, its just too common/likely a name for variables/fields & functions/methods. 
Who hasn't written a class with a .restart() method before?

Reason two:

# { bool _sentinel; do { _sentinel = false;
#   foreach (i, x; some_collection) {
#     /*...do stuff...*/
#     if (/*...some condition...*/) {
#       _sentinel = true;
#       break;
#     }
#   }
# } while (_sentinel); }

Not particularly pretty, no, but it gets the job done and (IMHO) reads decently enough. 
If 'restart' adds some optimization ability this convention does not, then fine, so be 
it... just, can we please find another name, because Reason One is the big one to me.

-- Chris Nicholson-Sauls



More information about the Digitalmars-d mailing list