Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!harvard!husc6!panda!genrad!decvax!cca!g-rh From: g-rh@cca.UUCP (Richard Harter) Newsgroups: net.lang.c Subject: Re: What should be added to C Message-ID: <8126@cca.UUCP> Date: Fri, 30-May-86 02:04:29 EDT Article-I.D.: cca.8126 Posted: Fri May 30 02:04:29 1986 Date-Received: Wed, 4-Jun-86 00:05:00 EDT References: <1462@mmintl.UUCP> <5498@alice.uUCp> <1497@mmintl.UUCP> Reply-To: g-rh@cca.UUCP (Richard Harter) Organization: Computer Corp. of America, Cambridge Lines: 59 Summary: break n is not a good idea In article <> greg@utcsri.UUCP (Gregory Smith) writes: >In article <1497@mmintl.UUCP> franka@mmintl.UUCP (Frank Adams) writes: > >>>> o Any sort of multi-level break statement. There is no syntacticly clean >>>> way of adding this to C. > >I don't agree. what about >statement ::= break ; > | break constant_exp ; > >e.g. break 2; >would break the current loop *and* the enclosing one. > This is a chestnut. 'break n' type constructs have been tried and found wanting. The problem is that it can make code maintenance messy -- any time you modify the code by adding a level of blocking you have to modify all enclosed break statements. Miss just one and its mystery bug time. The reason that multilevel breaks are a problem in C is as follows. There are two ways in which labels can be used, (a) as the name of a block, and (b) as a transfer address. Functions use labels to name blocks (the body of the function). Goto's use labels as transfer addresses. The clean way to implement multilevel breaks is to use labelled blocks and name the block you are escaping in the break statement. However labels within function bodies as transfer addresses. You have a conflict of usage here. Of course you could add a block keyword and an escape keyword, e.g. block a { .... block b { .... escape a; } .... } next_statement_after_a; The escape statement transfers control to the next statement after block labelled a. Fine, so far, looks clean, is clean. But are you sure you know where that statement is? Maybe what you want is this: begin a .... begin b .... escape a; end b .... end a where labelled begins and ends delimit blocks. Does this (you should excuse the expression) begin to sound familiar, PL/I fans? Personally I think this approach has its points, but it's starting to stray a fair bit from C. Richard Harter, SMDS Inc.