src/swipl-devel/packages/xpce/man/refmanual/md/if.md

class if {#class-if}

An if object is a conditional statement. When executed, it will execute the <-condition. On success, it will execute the <-then branch, otherwise it will execute the <-else branch. An empty <-then or <-else (@nil) simply succeeds.

A special trick is to use if(<Statement>). This will succeed regardless of the success or failure of .

The following example exploits the if object to remove all graphicals with area <-measure: 0 from Device:

send(Device?graphicals, for_all,
     if(@arg1?area?measure == 0,
        message(@arg1, free)))

Class when implements the function equivalent of class if.

@see class when

Instance variables {#class-if-instvars}



Try the rswipl package in your browser

Any scripts or data that you put into this service are public.

rswipl documentation built on June 16, 2026, 5:07 p.m.