Break Continued

COTTRELL, JAMES cottrell at nbs-vms.ARPA
Wed Oct 2 11:09:19 AEST 1985


/*
> > 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,...
> 
> Well, now we know that this cat's either got some impressive coding
> techniques or doesn't use switch statements.  There are only two uses of
> break, namely to exit the middle of a loop or to get out of (and usually
> terminate) a branch of a switch.  If switch is used without break, I'd like
> to see how the coding works.  Other than that, using break only to get out
> of the middle of a loop is fairly unspectacular(!).

Here's how he does his switches! It *really* works (under bsd 4.2 at least)

main(argc)
{	int never = 0;
	switch (argc) {			/* switch man sleepin' */
	case 1:				/* train a hundred & two */
		printf("argc = 1\n");	/* is on the wrong track */
		if (never) {		/* & headin' for you! */
	case 2:		printf("argc = 2\n");
			if (never) {
	case 3:			printf("argc = 3\n");
				if (never) {
	case 4:				printf("argc = 4\n");
					if (never) {
	default:				printf("argc = ???\n");
}	}	}	}	}	}

Impressed? Well, you *did* ask! :-)

> Dick Dunn	{hao,ucbvax,allegra}!nbires!rcd		(303)444-5710 x3086
>    ...If you plant ice, you're gonna harvest wind.

I'm not entirely sure I agree with you about adding construx to the
language tho. I once saw this thruout a bunch of sources:

	#define	repeat(x,n)	for (x = 0; x < n; x++)

On the other hand, if *that's* what it takes to scare off everyone
from modifying my code, then macros away! :-)
Whichever way your pleasure tends...

	jim		cottrell at nbs
*/
------



More information about the Comp.lang.c mailing list