Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1exp 10/6/83; site ihuxa.UUCP Path: utzoo!linus!decvax!harpo!gummo!whuxle!pyuxll!eisx!npoiv!npois!hogpc!drux3!ihnp4!ihuxa!dixon From: dixon@ihuxa.UUCP Newsgroups: net.lang.c Subject: Re: the 'broken' statement Message-ID: <301@ihuxa.UUCP> Date: Fri, 7-Oct-83 14:26:06 EDT Article-I.D.: ihuxa.301 Posted: Fri Oct 7 14:26:06 1983 Date-Received: Sun, 9-Oct-83 08:03:10 EDT Organization: AT&T Bell Labs, Naperville, Il Lines: 65 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@utzoo.UUCP (Henry Spencer) >>Newsgroups: net.lang.c >>Subject: the 'broken' statement >>Message-ID: <3232@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@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 >> ELSE >> 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) { if(condition) { found it; break; /*stop loop when first value is found *such that 'condition' is satisfied */ } else 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