the 'broken' statement

Guy Harris guy at rlgvax.UUCP
Tue Oct 11 06:58:03 AEST 1983

I suspect the construct

	FIRST i IN something-that-generates-a-sequence-of-values
	SUCHTHAT condition
		found it
		not found

was supposed to be equivalent to

		for (first value; ;next value) {
			if (condition)
				goto found;

		not found;
		goto join;

		found it;


not to:

		for(first value; ;next value) {
			if (condition) {
				found it;
				break;		/*stop loop when first value
						 *is found such that 'condition'
						 *is satisfied
			} else
				not found;

I.e., the "found it" and "not found" clauses are executed when the loop
is finished; the first is executed if the loop terminated because the object
was found, and the second is executed if the loop terminated because it ran
out of values.  It does require a bunch of "goto"s and is a bit of a pain
to code (no claim is made here whether adding it to C would be a bigger or
smaller pain).

	Guy Harris

More information about the Comp.lang.c mailing list