Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!greg From: greg@utcsri.UUCP (Gregory Smith) Newsgroups: net.lang.c,net.lang.pascal Subject: Re: Pascal vs C, again (was: Pascals Origins) Message-ID: <3130@utcsri.UUCP> Date: Fri, 18-Jul-86 14:14:43 EDT Article-I.D.: utcsri.3130 Posted: Fri Jul 18 14:14:43 1986 Date-Received: Fri, 18-Jul-86 14:32:47 EDT References: <2222@brl-smoke.ARPA> <7014@boring.mcvax.UUCP> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 45 Summary: In article <7014@boring.mcvax.UUCP> jack@boring.uucp (Jack Jansen) writes: > >I'm getting sick and tired of all those people picking on pascal, >and saying "C is better", without giving *any* reason for it. > : >You can say a lot of things about pascal, but not that it wasn't >well-designed. And, even though you have to do very wierd things >to get some things to work, it *is* possible to write medium to 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. - 'a or b', 'a and b' always evaluate both a and b ( I think this is a rule in Jensen & Wirth ) 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