Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!think!paperboy!meissner From: meissner@osf.org (Michael Meissner) Newsgroups: comp.lang.misc Subject: Re: do...while vs. repeat...until (was: Errors aren't that simple) Message-ID: Date: 24 Mar 90 13:44:04 GMT References: <16188@haddock.ima.isc.com> <9130009@hpavla.AVO.HP.COM> <16249@haddock.ima.isc.com> <4879@ganymede.inmos.co.uk> Sender: news@OSF.ORG Organization: Open Software Foundation Lines: 33 In-reply-to: mph@lion.inmos.co.uk's message of 23 Mar 90 12:51:41 GMT In article <4879@ganymede.inmos.co.uk> mph@lion.inmos.co.uk (Mike Harrison) writes: | >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.) Three things: 1) On EBCDIC systems, either of the above tests would evaluate true for some things that are not lower case alphabetic, since there are some characters (10?) between 'i' & 'j'; 2) Obviously the above test will not work for character sets that have more than 26 alphabetic characters; 3) If you are worried about micro optimization, and your compiler doesn't recognize the optimization, you generally get faster code if you rewrite the test as: if (((unsigned) c - 'a') <= ((unsigned) 'z' - 'a')) This is because only one branch is done. -- Michael Meissner email: meissner@osf.org phone: 617-621-8861 Open Software Foundation, 11 Cambridge Center, Cambridge, MA Catproof is an oxymoron, Childproof is nearly so