Which solution for my small problem would you consider a better style? Is there another better option that I am missing?
The logic is simple: Process data from a source until you get the
I have couple of imperfect ideas:
line = read_from_source() while line != "END": process(line) line = read_from_source()
I am actually calling
read_from_source() twice when the natural language description of the issue is calling it once. Potential for a maintenance bug when someone changes one place and forgets the other.
while True: line = read_from_source() if line == "EOF": break process(line)
I somehow dislike this as the loop condition doesn't stand out clearly from the code when glancing at it.
while line = read_from_source() != "END": process(line)
Concise, but I find it tough to raed when assignment and equality operator are on the same line.