jmc@root44.UUCP (John Collins) (08/17/83)
Could some guru acquainted with the history of C tell my why when Dennis Ritchie got hold of BCPL he changed the 'endcase' statement, merging it with 'break'? For those who don't know, BCPL allows 'loop' (equivalent to 'continue' in C), 'break', to get you out of the innermost loop, and 'endcase' to get out of the innermost 'switchon' statement (equivalent to 'switch'). Thus whereas in C you might have to write while (foo) { ..... switch (bar) { case ... ..... goto endloop; case ... .... continue; case ... break; } .... } endloop: in BCPL you could replace this with while foo do { ..... switchon (bar) into { case ... ..... break; case ... .... loop; case ... endcase; } .... } Apart from anything else, there is a aesthetic element, in that 'break' always takes you contextually further than 'loop/continue'. Please note that I am NOT arguing for an automatic jump prior to every new 'case' statement (a horrid idea which some people advocate). If I would like any one thing, it would be to have something like the 'break n' 'continue n' statements of 'sh'. John Collins ...!vax135!ukc!root44!jmc
tw@hp-pcd.UUCP (Tw Cook) (08/25/83)
#R:root44:-414400:hp-pcd:36000002:000:1903 hp-pcd!tw Aug 24 22:56:00 1983 From hp-dcd!donn Tue Aug 23 20:01:16 1983 It was suggested that C might be changed to include a "break n" or equivalent for jumping out of nested constructs. I'm not advocating the change (or against it either) here, but rather suggesting an alternate syntax for the function. When I was in grad school, we had a variant of XPL (XPL/S) that literally *did not have* a goto or equivalent. Instead it had the normal "structured programming" constructs and "exit <label>" that was essentially a break n. The difference was that the label was placed at the beginning of the compound statement. For example (in C, more or less): for (;;) bigloop { ... while () middleloop { do littleloop { if () exit bigloop; } while (); } } --> The "exit bigloop" would transfer control to "-->". There are several advantages: 1) Removing middleloop would not break the program; a "break n" would have to be changed as well. 2) Once you think about it a bit, the labelling is natural; the construct says "get out of the construct I called ...". (I don't think anyone had any trouble identifying the construct I proposed deleting in 1 above.) 3) The guy who implemented it said it made the compiler much easier to do; the implied forward reference to labels never occurs as they must be declared to be used. It would also make most of the 'non-local' goto problems go away as it becomes impossible to jump into a construct. I didn't miss the goto very much, and given both exit <label> *and* continue <label> (which was not present in XPL/S), I don't think I would have missed it at all. My gist is that there is a clean way to provide the desired function, and "break n", a-la shell or Bliss isn't it. (The XPL/S guru at the time was Geoff Leach; my acknowledgements, wherever he may be.) Donn Terry [ucbvax]!hplabs!hp-dcd!donn csu-cs!hp-dcd!donn
ka@spanky.UUCP (08/27/83)
For the record, the multi-level break statement in Bliss does use labels (just like Ada and PL/1). The reason Ratfor and the shell use a count of the number of levels to break is probably to simplify the implementation by avoiding the need for a symbol table. This seems reasonable; I don't recall *ever* seeing a multi-level break or continue used in shell code. Certainly this is not a frequently used construct. Kenneth Almquist