Path: utzoo!attcan!uunet!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: Seven Original Sins of K&R (Long) Message-ID: <3846@goanna.cs.rmit.oz.au> Date: 28 Sep 90 04:14:12 GMT References: <12780@sdcc6.ucsd.edu> <4700066@m.cs.uiuc.edu> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 30 In article <4700066@m.cs.uiuc.edu>, gillies@m.cs.uiuc.edu writes: > Hey, how else can I write the following amazingly convoluted code > (idea courtest of Harbison & Steele's book, first edition): > main() > { > int x,i; > x=1; > switch(x) { > case 1: > for (i=0; i < 10; i++) > case 2: > printf("%d ",i); > } > } Easily: main() { int i; for (i = 0; i < 10; i++) printf("%d ", i); exit(0); /* you shouldn't leave this out */ } This was possible because of the assignment x=1. If that assignment had been x=2, the effect would have been undefined because i was not initialised. That's a good reason not to jump into loops even if C lets you. -- Fixed in the next release.