C 'break' command - a query

John Collins jmc at root44.UUCP
Wed Aug 17 20:35:56 AEST 1983


Could some guru acquainted with the history of C tell my why when Dennis
Ritchie got hold of BCPL he changed the 'endcase' statement, merging it with
'break'?

For those who don't know, BCPL allows 'loop' (equivalent to 'continue' in C),
'break', to get you out of the innermost loop, and 'endcase' to get out of
the innermost 'switchon' statement (equivalent to 'switch').

Thus whereas in C you might have to write

	while  (foo)  {
		.....
		switch  (bar)  {
		case ...
			.....
			goto  endloop;

		case ...
			....
			continue;

		case ...
			break;
		}
		....
	}
endloop:

in BCPL you could replace this with

	while  foo  do  {
		.....
		switchon  (bar)  into  {
		case ...
			.....
			break;

		case ...
			....
			loop;

		case ...
			endcase;
		}
		....
	}

Apart from anything else, there is a aesthetic element, in that 'break' always
takes you contextually further than 'loop/continue'.

Please note that I am NOT arguing for an automatic jump prior to every new
'case' statement (a horrid idea which some people advocate).

If I would like any one thing, it would be to have something like the 'break n'
'continue n' statements of 'sh'.

		John Collins
			...!vax135!ukc!root44!jmc



More information about the Comp.lang.c mailing list