the 'broken' statement

dixon at ihuxa.UUCP dixon at ihuxa.UUCP
Sat Oct 8 04:26:06 AEST 1983

The following article arrived here yesterday:

>>From ihnp4!clyde!floyd!whuxlb!gummo!harpo!decvax!linus!utzoo!henry Wed Dec 31 18:00:00 1969
>>Relay-Version: version B 2.10.1 7/20/83; site ihuxa.UUCP
>>Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP
>>Path: ihuxa!ihnp4!clyde!floyd!whuxlb!gummo!harpo!decvax!linus!utzoo!henry
>>From: henry at utzoo.UUCP (Henry Spencer)
>>Newsgroups: net.lang.c
>>Subject: the 'broken' statement
>>Message-ID: <3232 at utzoo.UUCP>
>>Date: Tue, 4-Oct-83 18:17:02 CDT
>>Article-I.D.: utzoo.3232
>>Posted: Tue Oct  4 18:17:02 1983
>>Date-Received: Thu, 6-Oct-83 01:05:18 CDT
>>References: <322 at ucbcad.UUCP>
>>Organization: U of Toronto Zoology
>>Lines: 18
>>Bill Wulf suggested some years ago that in addition to the FOR loop,
>>which is good for operating on all elements of a data structure, there
>>ought to be a FIRST loop for searching data structures:
>>	FIRST i IN something-that-generates-a-sequence-of-values
>>	SUCHTHAT condition
>>	DO
>>		found it
>>		not found
>>	END
>>(Ignore the exact punctuation, it was something like that.)  I always
>>thought this was a pretty neat idea.  It's far too late to retrofit
>>it to C, of course.
>>				Henry Spencer @ U of Toronto Zoology
>>				{allegra,ihnp4,linus,decvax}!utzoo!henry

This proposed construct can be implemented in C as follows:

	for(first-value-in-sequence-of-values; ;advance-to-next-value)
			found it;
			break;		/*stop loop when first value is found
					 *such that 'condition' is satisfied
			not found;

This code requires the same number of constructs as that used
in the above article and is reasonably straight forward. So,
the construct 'FIRST i IN' ...  provides only a small marginal
gain over existing C features. Maybe this marginal gain is not
worth the complications it would add to the C compiler.

D A Dixon       ihuxa!dixon      BTL - IH

More information about the Comp.lang.c mailing list