🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #824

Re: Why are the loops so awkward?

#824
From: WOLNIEWICZ RICHARD HANSON
Date: Fri, 15 Jun 1990 15:54
30 lines
2044 bytes
In article <26032@netnews.upenn.edu>
touch@dsl.cis.upenn.edu (Joe Touch) writes:
>I'd prefer
>
>	WHILE (index <= stringLength) AND (String1[index] = String2[index] DO
>		INC(index);
>	END; (* WHILE *)
>
>Unless my book is wrong, M2 is defined as having short-circuit evaluation
>of conjunctions and disjunctions.  So if the index is out of bounds,
>the string element comparison never occurs, and the AND is safe.

This is something I had never known before.  I assumed short-circuit
evaluation was in use, but I also (apparently incorrectly) assumed that the
compiler could evaluate the expressions in whatever order it found to be
optimal.  Could someone find the reference for this?  If this is true, I look
forward to taking advantage of it.

>This omits the use of a redundant boolean (logical) variable, 
>and not only is ir correct, but it will run faster (you don't
>really need to store the value of the comparison, do you?)

I think you do need that comparison result (remember my example was based upon
another netter's previous example).  Why compare two strings if you aren't
going to use the comparison result?

 .    .    ______      Laboratory for Atmpospheric and Space Physics
 |   / \  (__  ._)     University of Colorado, Boulder
 |__/   \____) |       Richard Wolniewicz (wolniewi@tramp.colorado.edu)
                       Disclaimer: Only the opinions of a grad student (me)
Technical Details
Message-ID: <22282@boulder.Colorado.EDU>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mailrus!ncar!boulder!wolniewi
References: <5377.26731960@puddle.fidonet.org> <728.26767558@waikato.ac.nz> <22213@boulder.Colorado.EDU> <747.2677cd57@waikato.ac.nz> <22259@boulder.Colorado.EDU> <26032@netnews.upenn.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mailrus!ncar!boulder!wolniewi
From: wolniewi@boulder.Colorado.EDU (WOLNIEWICZ RICHARD HANSON)
Newsgroups: comp.lang.modula2
Subject: Re: Why are the loops so awkward?
Message-ID: <22282@boulder.Colorado.EDU>
Date: 15 Jun 90 15:54:36 GMT
References: <5377.26731960@puddle.fidonet.org> <728.26767558@waikato.ac.nz> <22213@boulder.Colorado.EDU> <747.2677cd57@waikato.ac.nz> <22259@boulder.Colorado.EDU> <26032@netnews.upenn.edu>
Sender: news@boulder.Colorado.EDU
Reply-To: wolniewi@tramp.Colorado.EDU (WOLNIEWICZ RICHARD H.)
Organization: University of Colorado, boulder
Lines: 30