🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #878

Re: do...while vs. repeat...until (was: Errors aren't that simple)

#878
From: Peter Montgomery
Date: Fri, 16 Mar 1990 05:43
31 lines
2005 bytes
In article <16188@haddock.ima.isc.com> karl@haddock.ima.isc.com (Karl Heuer) writes:
>In article <5819.25f7a840@vax1.tcd.ie> cbuckley@vax1.tcd.ie writes:
>>In article <Mar.7.10.43.42.1990.17402@paul.rutgers.edu>, emuleomo@paul.rutgers.edu (Emuleomo) writes:
>>> The other less serious flaw in C is the do...while contruct.
>>> I kind of prefer PASCAL's repeat....until construct myself.
>>
>
>That's enough to make it a (minor) flaw.  Judging from my own personal
>experience, it is more natural for a test-at-top loop to specify the condition
>for continuing (while), but for a test-at-bottom loop to specify the condition
>for terminating (until).  I don't know if there's been a study on this; in
>fact, I'm not entirely sure how to formalize the concept.

	Another problem with do..while is that we cannot access
variables declared inside the block in the loop test.  For example,
when updating a square root by Newton's method, the code

		double sqrtx, x;
		sqrtx = (some approximation to sqrt(x))
		do {
		    register const double err = x - sqrtx*sqrtx;
		    sqrtx += err/(2*sqrtx);
		} while (fabs(err) > 0.001*x);

is illegal.  Rather, we must declare "err" in a larger scope.


--------
        Peter Montgomery
        pmontgom@MATH.UCLA.EDU 
	Department of Mathematics, UCLA, Los Angeles, CA 90024
Technical Details
Message-ID: <2401@sunset.MATH.UCLA.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!usc!elroy.jpl.nasa.gov!ucla-cs!math.ucla.edu!oak!pmontgom
References: <8192@hubcap.clemson.edu> <17000003@hpcvra.CV.HP.COM> <Mar.7.10.43.42.1990.17402@paul.rutgers.edu> <5819.25f7a840@vax1.tcd.ie> <16188@haddock.ima.isc.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!usc!elroy.jpl.nasa.gov!ucla-cs!math.ucla.edu!oak!pmontgom
From: pmontgom@oak.math.ucla.edu (Peter Montgomery)
Newsgroups: comp.lang.misc
Subject: Re: do...while vs. repeat...until (was: Errors aren't that simple)
Message-ID: <2401@sunset.MATH.UCLA.EDU>
Date: 16 Mar 90 05:43:42 GMT
References: <8192@hubcap.clemson.edu> <17000003@hpcvra.CV.HP.COM> <Mar.7.10.43.42.1990.17402@paul.rutgers.edu> <5819.25f7a840@vax1.tcd.ie> <16188@haddock.ima.isc.com>
Sender: news@MATH.UCLA.EDU
Reply-To: pmontgom@math.ucla.edu (Peter Montgomery)
Organization: UCLA Mathematics Department
Lines: 31