for loop counting backward?

Jegenye 2001 Bt jegenye2001 at fw.hu
Sun Oct 12 14:45:49 EDT 2003


for i in xrange(100,2,-1):
    do_something()

Mind the "fence rule" in Pythonic slices, i.e. xrange

Regards,
 Miklós

--
Prisznyák  Miklós
---
Jegenye 2001 Bt. ( jegenye2001 at (NoSPAM)parkhosting dot com )
Egyedi szoftverkészítés, tanácsadás
Custom software development, consulting
http://jegenye2001.parkhosting.com


Eric Wichterich <eric.wichterich at gmx.de> wrote in message
news:mailman.31.1065977869.2192.python-list at python.org...
> Hello,
>
> I am converting a perl-script to python and have problems with this
> simple perl-statement:
>
> for ( $i = 100; $i > 2; $i-- ) {do something }
>
> Does anyone know how to write this in python? I did not find any
> documentation about counting backward in a for loop...
>
> By the way:
> I converted following perl - statement:
>
> for $i ( 2 .. 100 ) { do something}
>
> into python:
>
> for counter in range(2,100)
> do something
>
> Thank you very much,
> Eric
>
>






More information about the Python-list mailing list