This program will run, as expected, until the input signals "end of file".
If you're not using input redirection (e.g. running it as myprogram < somefile.txt
) but instead running with the console (keyboard) as the input device, you must manually signal end of file to cause the loop to end.
In Linux, this is done by pressing Ctrl+D, in Windows it's Ctrl+Z.