Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!topaz!think!mit-eddie!genrad!decvax!decwrl!amdcad!cae780!tan From: tan@cae780.UUCP Newsgroups: net.lang.c,net.lang.pascal Subject: Re: Pascal vs C, again (was: Pascals Origins) Message-ID: <2473@cae780.UUCP> Date: Mon, 28-Jul-86 21:26:19 EDT Article-I.D.: cae780.2473 Posted: Mon Jul 28 21:26:19 1986 Date-Received: Wed, 30-Jul-86 00:33:25 EDT References: <2222@brl-smoke.ARPA> <7014@boring.mcvax.UUCP> <3130@utcsri.UUCP> Organization: Tektronix, Inc. (CAE Systems Division), Santa Clara, CA Lines: 78 Summary: Choose whatever you like Xref: mnetor net.lang.c:5486 net.lang.pascal:348 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. > > Further rules: > - Standard Jensen & Wirth Pascal ( no break from loop ) > - *** x[i] must not be evaluated for i<1 or i>1000 *** > - The search loop must be terminated as soon as a zero is found. > > This is the best I can find: > var i: integer; > ... > i :=1 ; > while i<1000 and x[i] <> 0 do > 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. > > Nobody can call this a special case... and I don't think my rules are > unreasonable. The problem is the behaviour of 'and' plus the lack of 'break'. > > -- > "You'll need more than a Tylenol if you don't tell me where my father is!" > - The Ice Pirates > ---------------------------------------------------------------------- > Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg I don't like your challenge. If breaking out of a loop can't be considered as a language feature for Pascal (although it is an extension to the original Pascal language construct, it is more than common in these days), we can't consider the 'enum' construct as a legal feature for C, and anyone who come up with a 'challenge' that needs the service of this 'enum' monster would have thrash C. I suggest that broader view be taken into account when one tries to 'compare' a programming with the other. The fully evaluation of conditional expression in Pascal may cause some problem to some people, but they are not hard to get around. The argued 'x[i] = 0 got executed twice == expensive' does not hold, since one such comparison is peanut compared to, say, 100 such operations. For the case of 'extremely complicated' data structure, PLEASE use a flag. I have done some 'medium' programs using both languages. I don't have any pro or con on both of them. I like and hate Pascal that it 'force' me into a rigid track in programming. I hate it because it takes me shorter time to complete my programs, even worse, it is so readable that anyone can take over my job at anytime ! I love and hate C also. She gives me the luxury to fool around with whatever possible. I love her 'cause I know I have a safe job. No, I don't love C that much, once it took me weeks to found out that I 'accidentally' lost one of my mantissa bit in one of my crazy functions in the 'greatest' program I have ever written (neat eh?). Oh ya, you definately can full Pascal by using variant record, but it is more fun doing it in C. The beauties of both miss C and Mr Pascal have been globally ad. Sorry for not including these ad's in this article for I am not an ad. agent. ---------------------------------------------------- - - - I speak for myself only. - - - ----------------------------------------------------