do loop

beliavsky at aol.com beliavsky at aol.com
Fri Jan 16 08:36:07 EST 2004


In a Python 'for' loop, one can change the value of looping variable,
so that

for i in range(3):
    i = i*5
    print i

is legal code

In Fortran 90 and 95, the analogous code

do i=0,2
   i = i*5
   print*,i	
end do

is illegal, because variable 'i' cannot be changed inside the loop.
The constraint of not allowing the loop variable to change within the
body of the loop can prevent errors in logic when the body of the loop
is large.

Is there a way to write a loop in Python that enforces this
constraint? Should such functionality be added to the language?



More information about the Python-list mailing list