only one loop over the lines in the file

instead of iterating over the lines multiple times, just iterate once and analyze lines one by one