Scope of switch statements

Henry Spencer henry at utzoo.uucp
Thu Nov 16 04:29:03 AEST 1989


In article <301 at guardian.UUCP> peter at langlab1.hf.intel.com (Peter Plamondon) writes:
>|>    switch(i) {
>|>      case 0: for(; ++k % 3; ++j) {
>|>      case 1:   printf(" j = %d,", j);
>|>      case 2:   printf(" k = %d,", k);
>|>              }
>|>    }
>
>I've stared at this and can't make sense of it.  Could someone provide me
>with enlightenment?

Rewrite it this way:

	if (i == 0)
		goto zero;
	else if (i == 1)
		goto one;
	else if (i == 2)
		goto two;
	else
		goto done;
zero:	for ... {
		one:	printf...;
		two:	printf...;
	}
done:

Yes, branching into a loop is disgusting, but it is legal.

Don't ask me what the code is supposed to *do*.
-- 
A bit of tolerance is worth a  |     Henry Spencer at U of Toronto Zoology
megabyte of flaming.           | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.std.c mailing list