[Tutor] what i miss is a C style for loop

Thomi Richards thomi@thomi.imail.net.nz
Tue, 22 Oct 2002 10:21:02 +1300


ahh well, i know that i can do while loops, but it just seemed to me
that for loops were somewhat "neater"....

thanks all the same :-)

On Mon, 21 Oct 2002 15:15:33 +0100 Thus said alan.gauld@bt.com:

> > yep, thats right, i live those C style for loops. they are 
> > compact, and easy to use, once you get the hang of it..
> 
> The C for loop is just a while loop in disguise 
> so you can duplicate the basic functions, but 
> the full C for loop power is not really feasible 
> in Python
> 
> for(a=0,b=5;c=b;a=0,b+=7){....}
> 
> for example. Valid if strange C but hard to do in any 
> sane python function.
> 
> But if you stick to the basic C style:
> 
> for(i=0;i<limit;i++){...}
> 
> Then you can do:
> 
> def cfor(initvalue,limit,incr, func):
>     i = initvalue
>     while i < limit:
>        func(i)
>        i += incr
> 
> But that's a poor imitation of a C for loop...
> 
> Also you need to allow access to the global 
> environment from within the loop without name 
> clashes etc...
> 
> Anything more potent would really be pretty 
> complex and probably very slow! 
> 
> Alan g.
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


-- 
DOS: n., A small annoying boot virus that causes random spontaneous
system
     crashes, usually just before saving a massive project.  Easily
cured by
     UNIX.  See also MS-DOS, IBM-DOS, DR-DOS.
(from David Vicker's .plan)
Thomi Richards,
thomi@imail.net.nz