Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: Notesfiles; site iuvax.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!inuxc!iubugs!iuvax!cjl From: cjl@iuvax.UUCP Newsgroups: net.lang.c Subject: Re: break, continue, return, goto Message-ID: <9500029@iuvax.UUCP> Date: Sun, 10-Nov-85 13:40:00 EST Article-I.D.: iuvax.9500029 Posted: Sun Nov 10 13:40:00 1985 Date-Received: Wed, 13-Nov-85 08:34:27 EST References: <771@whuxl.UUCP> Lines: 42 Nf-ID: #R:whuxl:-77100:iuvax:9500029:000:1705 Nf-From: iuvax!cjl Nov 10 13:40:00 1985 Craig made good suggestions for not using "continue" and "break" especially for the examples of Michael. "Continue" goto the beginning of the loop. Replacing it with "else" would make the logic flow of the codes following the "break" more smoothly. "Break" is generally interpreted as an exception where logic flow is disrupted. But for the searching problem, both found and not found are normal results. We can hardly interpret "not found" as an undesired result. In general exception, like error in system call, will lead to program abnormal termination. Error recovery is hard to achieve, because logic flow is disrupted. Too many times, programmers are seduced by the use of break for a quick solution without spending time to structure their program more. That is the same lesson we learned from advocating goto-less programs. In addition, I recommend the use of for loop be restricted to its original meaning in natural language, i.e. as a loop with simple counter. With more complicate exit conditions, while loop fits better : m = meeble; while ((m < meeble+NMEEBLE) && (m->glop==forp || m->zip==fweep)){ /* walk thru the array till we hit the end or * find the right one */ ++m; }; if (m < meeble + NMEEBLE) { /* found it */ printf("zeegle %2s", m->yorg); m->blazzo += IGUAP; } else { /* not found it */ } In some language like Pascal there is no conditional boolean operator, we have to use boolean flages. With the availability of && and || in C, exit conditions can be coded more explicitly than with boolean flags. C.J.Lo ARPA : cjl@Indiana@CSNet-Relay UUCP : ...!iuvax!cjl