Translate this to python?
Peter Hansen
peter at engcorp.com
Tue Jan 3 21:32:39 EST 2006
Patrick Maupin wrote:
>>for (i = nPoints-1, j = 0; j < nPoints; i = j, j++)
>
>
> A simple translation of this would be:
>
> i = npoints-1
>
> for j in range(npoints):
> ... (your code here)
> i = j
Though, without knowing what the body does, one can't be sure that's
going to be a faithful translation. The for loop in Python always
iterates over the entire set of items given to it, unless it's told to
break early. But if "j" or "nPoints" is modified in the body of the C
for loop, the loop might execute a different number of times than the
above Python for loop would.
(I agree it appears unlikely that the OP's code is going to do that, but
it's worth mentioning for safety.)
-Peter
More information about the Python-list
mailing list