Node:I/O Example, Previous:File Pred, Up:Input Output

An Example

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

process_file(F) :-
        see(F),                 % Open file F
          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

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.