Xref: utzoo comp.lang.misc:4566 comp.lang.c:27105 Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!snorkelwacker!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.misc,comp.lang.c Subject: Re: do...while vs. repeat...until (was: Errors aren't that simple) Message-ID: <16249@haddock.ima.isc.com> Date: 21 Mar 90 23:50:39 GMT References: <16188@haddock.ima.isc.com> <9130009@hpavla.AVO.HP.COM> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Followup-To: comp.lang.misc Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 35 (Followups to comp.lang.misc. I'm not talking about C; I'm talking about loop constructs in general.) In peter@ficc.uu.net (Peter da Silva) writes: >The only sense in which repeat...until is more natural than do...while is >if you're an assembly programmer or compiler writer [because at a low level, >both are branch-if-false]. That's one possible justification, but it certainly isn't "the only sense" in which it's more natural. To take a concrete example, let's ignore the existence of and suppose that we want to test whether or not a given character is a lowercase letter. I claim that, to me, the condition "(c >= 'a' && c <= 'z')" is a simpler expression than "(c < 'a' || c > 'z')". I immediately recognize the idiom in the former, but the latter causes a perceptible delay as I mentally translate the condition. (If you disagree with this example, invent another one--unless you want to claim that there is *no* condition that is simpler than its inverse.) Now, my observation is that, given a condition COND which is simpler than !COND, I am more likely to encounter the condition "do...while (!COND)" than "do...while (COND)". In this sense, repeat...until is the more natural construct. This is not a proof. It's an observation, possibly biased (though I don't think so) and subject to being contradicted by a more extensive study. Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint ________ (Note to those who keep on beating this red herring: the difference is *not* so significant that I'm willing to use it as an excuse to switch from C to another language; not even to that dialect of C that uses an "until" macro. So don't bother to point out that "the preprocessor can fix it". Do you think you're telling me something I don't know?)