Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site nsc.uucp Path: utzoo!linus!decvax!harpo!seismo!hao!menlo70!nsc!chongo From: chongo@nsc.uucp (Curt Noll) Newsgroups: net.lang.c Subject: Re: "Break" and other ways out of loops and switches Message-ID: <357@nsc.uucp> Date: Wed, 24-Aug-83 16:04:10 EDT Article-I.D.: nsc.357 Posted: Wed Aug 24 16:04:10 1983 Date-Received: Fri, 26-Aug-83 03:42:32 EDT References: <302@ihuxq.UUCP> Organization: National Semiconductor, Sunnyvale Lines: 59 > ... A high school student (!) that I help with his compiler over > occassional lunch hours came up with what I think is a super way out of > the multiple-level or multiple-construct break problem (i.e., breaking > out to the "right" level (the one you want)). He suggested labelling the > initial statement of the construct to be "broken" ... and then giving > the label as an "argument" to break. > ... other languages (such as BLISS) have this feature. I think that > it's great, would be relatively easy to add to compiler (I think), > and is even compatible with the current C. Multiple-level breaks are > a common reason for seeing one of those rare goto's in modern code. > This feature would eliminate the need those occurrances. Well, > what do do you think, yea or nay? > > Chris Scussel Bell Labs i say NAY to the high school suggestion regarding labeled multi-break. what that would do is to create another quasi-goto, and another way for obscene code to be created. try: /* more or less minus possible typos */ #define TRUE 1 #define FALSE 0 #define breakout( breakflag ) if ( breakflag ) { break; } #define multibreak( breakflag ) breakflag = TRUE; break #define setbreak( breakflag ) breakflag = FALSE #define testbreak( breakflag ) ! breakflag #typedef unsigned char BREAKFLAG ... BREAKFLAG stopreading; /* read process termination */ ... /* read lines of text ... */ for ( setbreak( stopreading ); some-code; some-code && testbreak( stopreading ) ) { ... /* character in line processing */ while ( some-code && testbreak( stopreading ) ) { ... /* case in char in a line */ switch ( some-code ) { ... case SOMETHING: ... multibreak( stopreading ); /* stop reading */ break; /* for readability */ ... } breakout( stopreading ); /* termiate loop */ } breakout( stopreading ); /* terminate loop */ } any number of ways can be constructed in C to do similar things. chongo /\../\