in reply to Re^4: A way to avoid repeated conditional loops
in thread A way to avoid repeated conditional loops

Ah! Now I see what you're saying.

Using AR's code, suppose the file is empty, then the very first while (<FILE>) will return EOF, then the code flows to the second while (<FILE>). There, even though the file pointer is at the end of the file, the <> operator won't return an EOF a second time. And the code in that second while loop will get executed when it should not.

Thinking of it this way, I can now see how both yours and JavaFan's code avoid that trap. Thanks.

  • Comment on Re^5: A way to avoid repeated conditional loops