This can be answered by finding out if Jeff lectures in a subject which fred studies.
Subject is a variable.
The question consists of two goals . To answer this question, Prolog first finds a course, Subject, for which Jeff is the lecturer and then finds out if Fred studies the Subject which was just found. Prolog solves this problem by proceeding left to right and then backtracking . A good way of picturing what happens when Prolog tries to find a solution and backtracks, is to draw tree diagrams like the one on the next page. After the first solution is found, Prolog retraces its steps up the tree and looks for alternative solutions.