Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version nyu B notes v1.5 12/10/84; site csd2.UUCP Path: utzoo!linus!philabs!cmcl2!csd2!dimitrov From: dimitrov@csd2.UUCP (Isaac Dimitrovsky) Newsgroups: net.lang.c Subject: Re: break, continue, return, goto (net.religion.c) Message-ID: <3090010@csd2.UUCP> Date: Thu, 14-Nov-85 17:10:00 EST Article-I.D.: csd2.3090010 Posted: Thu Nov 14 17:10:00 1985 Date-Received: Fri, 15-Nov-85 20:38:14 EST References: <516@busch.UUCP> Organization: New York University Lines: 60 [] > Can anyone suggest a recoding of the following example without using > multiple returns? Of course it can be done, but in a clearer, simpler > way? Remember, this is exactly the same as using loops with continue. > > core(file) > char *file; > { > if ((fd = open(file, O_RDONLY)) < 0) { > perror(file); > return; > } > if ((n = read(fd, &u, sizeof u)) == 0) { > puts("zero length"); > return; > } > if (n < sizeof u) { > puts("too small"); > return; > } > if (BADMAG(u.u_exdata.ux_magic)) { > puts("not a core dump"); > return; > } > > /* process core dump */ > printf("%d/%d %s", u.u_uid, u.u_gid, ctime(&u.u_start)); > printf("$ %s\n", u.u_comm); > /* ... etcetera */ > } core(file) char *file; { if ((fd = open(file, O_RDONLY)) < 0) perror(file); else if ((n = read(fd, &u, sizeof u)) == 0) puts("zero length"); else if (n < sizeof u) puts("too small"); else if (BADMAG(u.u_exdata.ux_magic)) puts("not a core dump"); else { /* process core dump */ printf("%d/%d %s", u.u_uid, u.u_gid, ctime(&u.u_start)); printf("$ %s\n", u.u_comm); /* ... etcetera */ } } Oh no!!! Not the straightjacket again!!! Gaaahhhhhrrgh.... Isaac Dimitrovsky allegra!cmcl2!csd2!dimitrov (l in cmcl2 is letter l not number 1) 251 Mercer Street, New York NY 10012 (212) 674-8652 ... Hernandez steps in to face ... Orl ... HERchiiiser ... and it's a liiine driive, deeeeep to the gap in left center ... - Bob Murphy, Voice of the Mets