[SciPy-user] stupid python question : for in in range(nlines) :

Ed Schofield schofield at ftw.at
Thu Apr 20 11:37:52 CDT 2006


Eric Emsellem wrote:
> Hi,
>
> I have a script including lines such as (reading a file with "nlines" 
> lines):
>
> ##############################
> for i in range(nlines) :
>     ...
>     ...
>     while i < nlines :
>       ....
>       i += 1
>       if ... :
>         break
> #############################
>   

I think you need to use a 'while' loop instead of 'for'.  For example:

i = 0
while i < nlines:
    ...
    ...
    while i < nlines :
      ....
      i += 1
      if ... :
        break
    i += 1


Hope this helps!

-- Ed



More information about the SciPy-user mailing list