Proposal of a general do-while loop

BCS ao at pathlink.com
Tue Jul 17 13:30:32 PDT 2007


Reply to Tristam,

> While we are at it, why not just this?
> 
> goto mid;
> begin:
> cc;
> mid:
> aa;
> if (bb) goto begin;
> Clear concise and simple, plus it is much closer to the actual machine
> logic, and so may imrpove performance as much as -1% ;)
> 

While your point is relevant, the actual reason for doing it the way I pointed 
out is not performance, but the removal of duplicate source code. I am a 
firm believer in the assertion that anytime you have duplication of code[*], 
you have a bug waiting to happen.

Except for the goto, my example read reasonably clearly and does a reasonable 
job of describing what is intended. The original proposal and the other examples 
(except maybe the if()break; example) are not, IMHO, so clear. If you can 
think of a better way to show the intent, I'm interested.

*IIRC the XP folks will agree with me, however I'm only looking at code that 
is /exactly/ the same, not just abstractable to the same thing.





More information about the Digitalmars-d mailing list