When read/1 encounters the end of a file it returns the Prolog atom
end_of_file
So we can rewrite test/0:
test:- read(X), \+(X = end_of_file), double(X,Y), write(Y), nl, test.
read(X),
\+(X = end_of_file),
\+
double(X,Y),
write(Y),
nl,
test.