"Lenard Lindstrom" <[EMAIL PROTECTED]> wrote:
> Pascal has no break, continue or return. Eiffel doesn't even have a > goto. In such imperative languages boolean variables are used a lot. Thanks did not know this. > > from StringIO import StringIO > lines = StringIO("one\ntwo\nthree\nfour\n") > line_number = 0 > eof = False > found = False > while not (eof or found): > line = lines.readline() > eof = line == "" > found = line == "three\n" > if not found: > line_number += 1 > > > if found: > print "Found at", line_number > else: > print "Not found" > # prints "Found at 2" > All right, so it is possible, with some legerdemain, forcing the main loop to stop when the condition is met. However, I find the above as clear as mud, compared to: line_number = 0 for line in my_file: line_number += 1 if "the Target" in line: break print line_number, line - Hendrik -- http://mail.python.org/mailman/listinfo/python-list