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

Tim Smith tim at callan.UUCP
Sun Jan 13 06:55:54 AEST 1985


Turnh on :-) mode.

In the two methods for breaking loops:

	/*						/*
	 * Method A					 * Method B
	 */						 */
	loop:	while ( foo )				while ( foo )
		{					{
			.					.
			.					.
			break loop;				goto endloop;
			.					.
		}					}
						endloop:;

many people seem to prefer A, because the label is at the start of the
loop, rather than at the end of the loop.

It seems to me that the obvious thing to do is to change the goto statement.
Goto should have the form

		goto	label [ {+,-} constant_expression ] ;

The constant expression tells how many statements away from the label
to 'goto'.  For example, the while loop break would be written like this:

	/*
	 * Method C
	 */
	loop: while ( foo )
	      {
		      .
		      .
		      goto loop + 1;
		      .
	      }

Exit :-) mode

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



More information about the Comp.lang.c mailing list