Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcvax!jack From: jack@mcvax.uucp (Jack Jansen) Newsgroups: net.lang.c,net.lang.pascal Subject: Re: Pascal vs C, again (was: Pascals Origins) Message-ID: <7017@boring.mcvax.UUCP> Date: Mon, 21-Jul-86 06:53:11 EDT Article-I.D.: boring.7017 Posted: Mon Jul 21 06:53:11 1986 Date-Received: Tue, 22-Jul-86 00:33:20 EDT References: <2222@brl-smoke.ARPA> <7014@boring.mcvax.UUCP> <3130@utcsri.UUCP> Reply-To: jack@boring.uucp (Jack Jansen) Organization: AMOEBA project, CWI, Amsterdam Lines: 37 Xref: mnetor net.lang.c:5384 net.lang.pascal:333 Apparently-To: rnews@mcvax In article <3130@utcsri.UUCP> greg@utcsri.UUCP (Gregory Smith) writes: > >Challenge: given > >var x: array [1..1000] of integer; > >write a code fragment to find the location of the first 0 in x. The >condition that no zeroes exist must be distinguished. >... >This is the best I can find: > var i: integer; > ... > i :=1 ; > while i<1000 and x[i] <> 0 do ^ Type of operands conflict :-) > i := i+1; > if x[i] = 0 then writeln('zero at location', i ) > else writeln('not found'); > >weird,huh? Note that the condition 'x[i]=0' is evaluated twice ( once >in the negative sense ), which would be unacceptable if we were searching >an array of records and the test was expensive. > Sigh, I shouldn't go into this, but I can't resist. First, what you do here is take a feature that is missing from pascal, and show a use for it. I *know* break is nice, and I *know* that it is missing from pascal. However, I could also come up with some nice question that would be ideally suited to use set's for, and you would have to come up with quite an ugly solution in C. Moreover, your statement about 'x[i]=0' being evaluated twice is not true. Don't forget that x[i]=0 is also evaluated for every time through the loop, so you just save one test in C.... -- Jack Jansen, jack@mcvax.UUCP The shell is my oyster.