[Tutor] Losing the expressiveness of C's for-statement?
Stephen McInerney
spmcinerney at hotmail.com
Tue Aug 7 11:18:16 CEST 2007
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
_________________________________________________________________
More photos, more messages, more storageget 2GB with Windows Live Hotmail.
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_2G_0507
More information about the Tutor
mailing list