"break <label>" vs. "goto <label>"

Rob Warnock rpw3 at redwood.UUCP
Sat Jan 19 08:54:08 AEST 1985


+---------------
| How are 'do' loops to fit in with 'break label'?
| Does the 'label' go with the 'do' or the 'while'?
| 	Tim Smith | 	ihnp4!wlbr!callan!tim or ihnp4!cithep!tim
+---------------

The label goes with the "do", since it is a "do" statement. "Break <label>"
says: "Go to just outside the labelled statement". (See K & R for "statement".)

Keep in mind, that any "break <label>" should also (for orthogonality) work
on a "compound statement", not just on loops. The semantics are the same. The
normal "continue" construct can be thought of as a "break <label>" for which
the labelled statement is the loop BODY, not the loop itself.

	while (...){			while (...)  zork:{
		...				...
		if (...) continue;		if (...) break zork;
		...				...
	}				}

The application to multi-level loops is straightforward.

p.s. If we're going to change the language, I vote for the generic
"leave <label>" of any labelled statement (a. la. BLISS), rather than
twisting the meanings of the current "break" and "continue".


Rob Warnock
Systems Architecture Consultant

UUCP:	{ihnp4,ucbvax!dual}!fortune!redwood!rpw3
DDD:	(415)572-2607
USPS:	510 Trinidad Lane, Foster City, CA  94404



More information about the Comp.lang.c mailing list