title: Prolog, skip adding elements to a list based on rules
body: <p>I have some Prolog code, and would like to be able to skip adding an element to the Results list if the product of X and Y is greater than a certain value. Any idea how I would go about doing this? </p>
  
  <p>e.g. </p>
  
  <pre><code>if Product &gt; 10
  </code></pre>
  
  <p>The code I have so far</p>
  
  <pre><code>make_quads(_,[],[]).
  make_quads(X,[Y|TAIL],[[X,Y,Sum,Product]|Result]):-
      make_quads(X,TAIL,Result),
      Product is X * Y,
      Product &gt; 2,
      Sum is X + Y.
  </code></pre>
  
  <p>The function is called as follows:</p>
  
  <pre><code>?- make_quads(5, [1,2,3,4,5,6], X).
  </code></pre>
  
  <p>Which would give the following output:</p>
  
  <pre><code>X = [[5, 1, 6, 5], [5, 2, 7, 10], [5, 3, 8, 15], [5, 4, 9, 20], [5, 5, 10, 25], [5, 6, 11|...]]
  </code></pre>
  
  <p>I've tried something along the lines of the following, but SWI-Prolog returns false as soon as I call the function</p>
  
  <pre><code>make_quads(_,[],[]).
  make_quads(X,[Y|TAIL],[[X,Y,Sum,Product]|Result]):-
      make_quads(X,TAIL,Result),
      Product is X * Y,
      Product &gt; 20, % I need to skip here
      % Else continue running
      Sum is X + Y.
  </code></pre>