Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site calgary.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!hao!hplabs!hpda!fortune!amd!dual!zehntel!ihnp4!alberta!calgary!radford From: radford@calgary.UUCP (Radford Neal) Newsgroups: net.lang.c Subject: Re: Breaking out of several nested loops (& ANSI C) Message-ID: <645@calgary.UUCP> Date: Wed, 10-Oct-84 15:17:26 EDT Article-I.D.: calgary.645 Posted: Wed Oct 10 15:17:26 1984 Date-Received: Sat, 13-Oct-84 04:19:45 EDT References: <129@ssc-vax.UUCP>, <1801@pegasus.UUCP>, <1518@wateng.UUCP> Organization: U of Calgary, Calgary, Alberta Lines: 52 I think labelling loops and allowing one to break out of several by using that label is NOT a good idea for the ANSI standard. What does this really get you? Nothing as far as I can see. Breaking out of nested loops with a goto is not at all obscure. The only advantage of a multi-level exit from a structured programming point of view is that it guarantees that only forward branches are made, presumably increasing readability. The proposal manages to avoid this advantage, however, by using the same syntax for a label used as the object of a goto as for a label used in a break. If I came across a label at the beginning of a while loop, my first impression would be that someone RESTARTS the loop by jumping there. If you really want to do such things, the best construct is the "situation case" proposed by C. T. Zahn. This works like this: notice-situation, , ... ... "> ... case
: case
: ... end (This isn't a proposal for a C-oriented syntax.) In the block of code at the beginning, statements can occur indicating that a particular situation has occured (possibly in deeply nested contexts). After this block are a number of (optional) sections of code that get jumped to when the corresponding situations arise. After that section of code is done, the statement following all this gets done. This gets you multi-level exits and more as well, in a potentially more understandable form. REALLY though, none of this is neccessary. I find that single level exits are quite convenient 95% of the time, and gotos work fine for the rest. I really thought this was all settled five years ago during the great structured programming debate. Using a goto statement once every few thousand lines of code is perfectly reasonable. Furthermore, this is just the sort of thing which should NOT go in a standard, as it would render all existing compiler non-standards-conforming for no good reason, reducing the probability that the standard will be taken seriously. Anybody who went out and wrote lots of code using the new construct thinking it was portable because it was "standard" would be fooling themselves. Radford Neal Dept. of Computer Science University of Calgary