"Break" and other ways out of loops and switches

cscussel at ihuxq.UUCP cscussel at ihuxq.UUCP
Tue Aug 23 12:30:44 AEST 1983


The recent article asking why "break" replaced "endcase" reminded me of the
following. 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" (e.g., the "for" statement)
and then giving the label as an "argument" to break. This binds the break
to the construct that it's suppossed to break, even if intervening code
is deleted or added. It's reminiscent of the way some people comment
their code (e.g., break; /* end scan */ becomes  break scan ; ). 
This idea was original with this student, although I've since found out
that 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
				Naperville, Illinois
				ihuxq!cscussel



More information about the Comp.lang.c mailing list