C 'break' command - a query - (nf)

Tw Cook tw at hp-pcd.UUCP
Thu Aug 25 17:35:02 AEST 1983


#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



More information about the Comp.lang.c mailing list