Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utcs!mnetor!seismo!brl-adm!caip!ut-sally!utah-cs!b-davis From: b-davis@utah-cs.UUCP Newsgroups: net.lang.c,net.lang.pascal Subject: Re: Pascal vs C, again (was: Pascals Origins) Message-ID: <3859@utah-cs.UUCP> Date: Mon, 21-Jul-86 20:28:48 EDT Article-I.D.: utah-cs.3859 Posted: Mon Jul 21 20:28:48 1986 Date-Received: Tue, 22-Jul-86 09:08:02 EDT References: <2222@brl-smoke.ARPA> <7014@boring.mcvax.UUCP> <3130@utcsri.UUCP> <8069@duke.duke.UUCP> Reply-To: b-davis@utah-cs.UUCP (Brad Davis) Organization: University of Utah VCIS Group Lines: 32 Xref: utcs net.lang.c:9836 net.lang.pascal:582 >In article <3130@utcsri.UUCP> greg@utcsri.UUCP (Gregory Smith) writes: > 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'); I personally like: for i := 1 to 1000 do if x[i] = 0 then goto DONE; i := 1001; DONE: if i <= 1000 then writeln('zero at location', i ) else writeln('not found'); If you don't like the 'goto' then flame someplace else. I think that goto's can be used in a structured manner. The statement 'i := 1001;' is needed since the value of 'i' is undefined after the 'for' statement. What's nice is that a good compiler can look at the 'for' loop and determine that bounds checking is not needed on the 'if' statement. The 'for' loop can also be done as a single machine instruction (on none RISC machines). A good optimizing compiler might even be able to generate better code than a good optimizing C compiler. I like Pascal for some reasons and I like C for other reasons. The reasons usually conflict. I don't claim to be consistant. -- Brad Davis {ihnp4, decvax, seismo}!utah-cs!b-davis b-davis@utah-cs.ARPA One drunk driver can ruin your whole day.