replaced for loop with a while loop

since writeLine() returns false when the read fails, we can just loop
through while readLine() returns true.