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

Guido van Rossum guido@digicool.com
Mon, 29 Jan 2001 21:57:24 -0500

> > - putting arbitrary initialization code in <init>
> Not sure what's "arbitrary", unless you mean unrelated to the 
> iteration variable.

Yes, that.

> 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.

And it rarely happens in Python, because sequences are rarely
represented as linked lists.

> 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?

Not dead set against something like it, but dead set against the ?:
syntax because then : becomes too overloaded for the human reader, e.g.:

    if foo ? bar : bletch : spam = eggs

If you want to revive this, I strongly suggest writing a PEP first
before posting here.

--Guido van Rossum (home page: http://www.python.org/~guido/)