[Python-Dev] Re: C's for statement

Eric S. Raymond esr@thyrsus.com
2001年1月29日 21:34:01 -0500


Guido van Rossum <guido@digicool.com>:
> Common abominations include:
>> - writing a while loop as for(;<test>;)

Agreed. Bletch.
 
> - putting arbitrary initialization code in <init>

Not sure what's "arbitrary", unless you mean unrelated to the 
iteration variable.
> - having an empty condition, so the <step> becomes an arbitraty
> extension of the body that's written out-of-sequence

Again agreed. Double bletch.
I guess my archetype of the cute C for-loop is the idiom for 
pointer-list traversal:
	struct foo {int data; struct foo *next;} *ptr, *head; 
	for (ptr = head; *ptr; ptr = ptr->next)
		do_something_with(ptr->data)
This is elegant. It separates the logic for list traversal from the
operation on the list element.
Not the highest on my list of wants -- I'd sooner have ?: back. I submitted
a patch for that once, and the discussion sort of died. Were you dead
det against it, or should I revive this proposal?
-- 
		<a href="http://www.tuxedo.org/~esr/">Eric S. Raymond</a>
"The bearing of arms is the essential medium through which the
individual asserts both his social power and his participation in
politics as a responsible moral being..."
 -- J.G.A. Pocock, describing the beliefs of the founders of the U.S.

AltStyle によって変換されたページ (->オリジナル) /