Ivan Jozsef Balazs wrote:This is suspicious. What should stop this loop?
Ivan Jozsef Balazs wrote:Once the value of numCharsRead is set, it does not change any longer, so this is an endless loop here:
Whereas here numCharsRead is reevaluated with every iteration, so it is possible for the loop to terminate.
It is indeed a typical construct going back to good old C times:
Ivan Jozsef Balazs wrote:
Every time the while condition is checked, it includes an evaluation of the expression numCharsRead = reader.read(charArr), that is, charArr will be filled by reading from reader, and the number of the read bytes will be assigned to numCharsRead. If it is positive, the core of the loop will be executed, and the loop continues, otherwise, the loop will be broken. The other aspects, I hope, you understand.