On 01/23/2013 03:56 PM, Coolgg wrote: > Is this: > > while True: > data = fp.read(4096) > if not data: > break > ... > > not equivalent to this: > > data = fp.read (4096) > while data: > ...{handle the chunk here} > data = fp.read (4096) > > Heres the article that sparked this question: > http://wordaligned.org/articles/pythons-lesser-known-loop-control
There is at least one potentially-critical difference: what happens if there is a 'continue' statement in the "..." part. The upper loop will set data again, while the lower one will not. So if what you mean is "are they equivalent no matter what legal Python code you put in the ...", no, they aren't. Evan
signature.asc
Description: OpenPGP digital signature
-- http://mail.python.org/mailman/listinfo/python-list