while true: !!!

Tim Peters tim.one at home.com
Mon Dec 11 13:34:50 EST 2000


[Jaroslav Gergic]
> one thing I dislike in many Python tutorials is
> the style of infinite 'while' loop with 'break' statements:
>
> > Python:
> >
> >     file = open('file.input')
> >
> >     count = 0
> >     while 1:
> >         lines = file.readlines(8192)
> >         if not lines: break
> >         count = count + len(lines)
> >
> >     print count
> >

That bothers me too, but for a different reason:  put the "break" on its own
line, so it's easy to see:

    while 1:
        lines = file.readlines(8192)
        if not lines:
            break
        count = count + len(lines)

there!-now-it's-perfect<wink>-ly y'rs - tim





More information about the Python-list mailing list