if/3

if(? G,? H,? I)*

Call goal H once per each solution of goal H. If goal H has no solutions, call goal I.

The built-in if//33is similar to @ref U60UU2dUU3eUU2fU_3 "->//3"3, with the difference that it will backtrack over the test goal. Consider the following small data-base:


 a(1). b(a). c(x).
 a(2). b(b). c(y).
```
`



`Execution of an if//33 query will proceed as follows:`



?- if(a(X),b(Y),c(Z)). X = 1, Y = a ? ; X = 1, Y = b ? ; X = 2, Y = a ? ; X = 2, Y = b ? ; no ``

The system will backtrack over the two solutions fora//11and the two solutions for @ref U60UbU2fU_1 "</tt>b//1"1, generating four solutions.``

Cuts are allowed inside the first goal __G__, but they will only prune over __G__.

If you want __G__ to be deterministic you should use if-then-else, as it is both more efficient and more portable.