while (a=b()) ...
William Tanksley
wtanksle at dolphin.openprojects.net
Sun May 2 16:24:02 EDT 1999
On Sat, 01 May 1999 14:27:21 -0700, Derek T. Jones wrote:
>wtanksle at dolphin.openprojects.net wrote:
>> On Thu, 29 Apr 1999 16:48:39 -0700 (PDT), Nathan Clegg wrote:
>> >I have some deep-rooted "hates" in programming and don't even know where
>> >some of them came from. One of them is "while 1" loops. They seem
>> >somehow at the same level as goto statements and should be used, in my
>> >mind, about as rarely.
>> I agree. Especially since while(1) loops require the use of a goto inside
>> of them.
>I disagree. A 'break' is not a 'goto'. The language Icon, which was
>part of Python's inspiration, has a 'repeat' loop which can only be
>broken out of with a 'break' statement. The idea of a loop whose exit
>condition must be, for design reasons, not either at the very beginning or
>the very end of the loop is not a kluge.
I should have said "essentially a goto", of course. break isn't goto, but
it's quite close in the sense that it should only be used in limited
cases, and only with due warning.
>The solution where the test method and the result method of the object
>in the loop are separate is, I believe, the nicest. But when the object
>you're working with doesn't provide that, then I vote for the "forever"
>loop.
Agreed. For no other reason than that nothing else is available.
[snipped: code convention to place the test-and-break at the top of the
loop]
>Reason: I feel it's easier to read and dispense with the exceptional
>conditions first, then save the normal case for the rest of the loop.
A very good convention. Does the FAQ list this? It likely should.
there's-only-one-true-way-to-do-anything-and-annoy-larry-by-being-post-post-
modern-or-is-that-structuralist-and-am-I-coming-close-to-setting-a-record-
for-length-and-possibly-self-referentiality-in-adverbial-salutations-ly yr's,
--
-William "Billy" Tanksley
"But you shall not escape my iambics."
-- Gaius Valerius Catullus
More information about the Python-list
mailing list