#### 11.3.102 `if/3`

#### Synopsis

`if(``+P`,`+Q`,`+R`)

*If* `P` *then* `Q` *else* `R`, for all solution of
`P`.

#### Arguments

`:P`
*callable*, must be nonvar

`:Q`
*callable*, must be nonvar

`:R`
*callable*, must be nonvar

#### Description

Analogous to

but differs from `P -> Q ; R`

in that `if(P, Q, R)`

explores
*all* solutions to the goal `P`. There is a small time
penalty for this—if `P` is known to have only one solution of
interest, the form `P -> Q ; R`

should be preferred.

This is normally regarded as part of the syntax of the language, but
it is like a built-in predicate in that you can write
`call(if(P,Q,R))`

.

Cuts in `P` do not make sense, but are allowed, their scope
being the goal `P`. The scope of cuts in `Q` and `R`
extends to the containing clause.

#### Backtracking

Depends on the arguments.

#### Exceptions

Call errors (see ref-sem-exc).

#### See Also

ref-sem.

Send feedback on this subject.