Translate this to python?
Peter Hansen
peter at engcorp.com
Tue Jan 3 21:29:14 EST 2006
KraftDiner wrote:
> I'm porting a routing from C++ to python.
> There is a complex for loop that I don't know how to code in python
>
> for (i = nPoints-1, j = 0; j < nPoints; i = j, j++)
i = nPoints - 1
j = 0
while j < nPoints:
# do stuff
i = j
j += 1
For loops in C aren't really complicated. They have stuff that happens
before the loop is entered, a test that occurs at the top of the loop
before each pass, and stuff that happens at the end of the loop just
after the body has executed. Using a while loop in Python makes it
mechanical to translate any such C for loop...
-Peter
More information about the Python-list
mailing list