On Fri, 22 Aug 2008 10:42:13 -0400, Ben Keshet wrote: > Thanks. I tried to use 'for' instead of 'while' as both of you > suggested. It's running well as my previous version but breaks > completely instead of just skipping the empty file. I suspect the > reason is that this part is inside another 'for' so it stops > everything. I just want to it to break only one 'for', that is go back > to 5th line in the example code (directory C has one empty file):
> for line in f: ^^^ > line = line.rstrip() > if "PRIMARY" not in line: > j += 1 > if j == 20: > break > else: > for line in f: ^^^ You're iterating through the same value in inner and outer loop. Don't do that. It's hard to predict the behavior of such a code. Regarding break statement, it breaks only the inner loop and returns to the outer loop/block. It would be great if you could reduce your code to a short piece that illustrates your problem and that we could all run. -- Regards, Wojtek Walczak, http://tosh.pl/gminick/ -- http://mail.python.org/mailman/listinfo/python-list