Newsgroups: comp.std.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Scope of switch statements Message-ID: <1989Nov15.172903.717@utzoo.uucp> Organization: U of Toronto Zoology References: <15743@bloom-beacon.MIT.EDU> <1989Nov9.200639.8868@utzoo.uucp> <301@guardian.UUCP> Date: Wed, 15 Nov 89 17:29:03 GMT In article <301@guardian.UUCP> peter@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@zoo.toronto.edu