An Example

Here is an example of a common form of file processing:

     process_file(F) :-
             seeing(OldInput),
             see(F),                 % Open file F
             repeat,
               read(T),              % Read a term
               process_term(T),      % Process it
               T == end_of_file,     % Loop back if not at end of file
             !,
             seen,                   % Close the file
             see(OldInput).
     

The above is an example of a repeat loop. Nearly all sensible uses of repeat/0 follow the above pattern. Note the use of a cut to terminate the loop.