I break for(;;) loops

COTTRELL, JAMES cottrell at nbs-vms.ARPA
Wed Oct 2 04:03:27 AEST 1985


/* Terry Poot writes:
> >	for (;;) {
> >		ch=getch();
> >		if ((ch>='1'&&ch<='5')||ch=='E') break;
> >		putchar(BELL);
> >	}
> Some of us feel the same about breaks as we do about gotos. I won't use
> it, or continue either, and I won't let anyone in my shop use it. It is
> just a goto with an implicit label, and destroys the ability to
> determine program flow from the FORM of the source even more
> drastically, as there is no label to catch your eye and alert you to the
> presence of the d*mned thing. The only way I will use a break is in a
> set of macros implementing a middle exit loop construct. We use
> LOOP...LOOPUNTIL...ENDLOOP. I know, adding features to a language with
> #define has problems, but at least that code is readable once you know
> what the constructs do, which is quite apparent. C should have that
> structure built in. Since it doesn't, we add it. The keywords are at the
> same indentation level, of course. 

Chicken! There is nothing wrong with a break statement. Most *real*
programmers don't have any difficulty with it, so why do you?
The fact that there is no label is a blessing, as then you can
jump there from *anywhere*, so you have to look for it. I suppose you
don't like `return's in the middle of a funxion either! Most of us
would rather see a well used break than an extra `if' statement
surrounding the `broken :-)' code and and extra boolean flag.

On the other hand, maybe C should have two kinds of breaks, one
for loops, one for switches. Multiple breaks have been discussed
before (please not again) & the general consensus seems to be
1) these aren't used too often & therefore there is no *pressing* need
2) you can easily miscount levels so just use a goto.

You will not receive my resume in the mail. Or many others.
 
> (-: Someone challenged me to produce flames. This should do it :-)

Yer durn tootin!


	jim		cottrell at nbs
*/

------



More information about the Comp.lang.c mailing list