(Question as below)

Sorry I meant to pick a tangible example to focus the discussion:

This one cannot be (easily) translated to use Python's range() operator
for (i=30000; i>0; i=i/2) { ... }

So do you need to know a whole armory of other functions to use
to generate iterators, or just translate to a while-loop already?

Stephen

From: "Stephen McInerney" <[EMAIL PROTECTED]>
To: tutor@python.org
Subject: Losing the expressiveness of C's for-statement?
Date: Tue, 07 Aug 2007 02:18:16 -0700

Hi all,

As the Python doc says: "The for statement in Python differs a bit from what you may be used to in C or Pascal. Rather than giving the user the ability to define both the iteration step and halting condition (as C), Python's for statement iterates over the items of any sequence (a list or a string)."

This is much poorer than C/C++, and does not allow for the step action to be multiple actions, fn calls etc. - not straightforwardly anyway. (don't take that as a challenge) - I know how to migrate to a while-loop, but I lament losing the very compact expressiveness of:
for (node=start; value<threshold && node!=end; node=node->next) { ... }
- I figure the straightforward answer will be "use a while-loop, put the iteration step at the end". - the fancy showoff answer will probably involve a funky iterator with side-effects, or returning tuples. - what if the loop iteration step involves variables from within the loop-body (e.g. as in quicksort stepsize); - what I'm trying to drive at here is the general solution of least idiomaticity, not of greatest language-specific cleverness

Any comments or article links? Also, it would be useful to improve the Python tutorial on this. Since this is one area where Python is (syntactically) inferior to C/C++/Java.

Thanks,
Stephen

_________________________________________________________________
Find a local pizza place, movie theater, and moreĀ….then map the best route! http://maps.live.com/default.aspx?v=2&ss=yp.bars~yp.pizza~yp.movie%20theater&cp=42.358996~-71.056691&style=r&lvl=13&tilt=-90&dir=0&alt=-1000&scene=950607&encType=1&FORM=MGAC01

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to