Prolog might be a "logic programming" language, but the flow control is explicitly based on backtracking. Each possible solution for each statement is iterated, one at a time, and the results are fed into the next statements. The program is basically run as a search through the constraints in depth-first order. http://www.doc.gold.ac.uk/~mas02gw/prolog_tutorial/prologpag...