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

class while {#class-while}

An instance of class while executes it's <-body until it's <-condition fails, similar to the Pascal or C while statement.

While loops are rarely used in XPCE. Most loops in XPCE entails enumerating the elements of a collection. For this purpose the methods chain ->for_all, vector ->for_all, etc. are more appropriate. The following two examples both print all elements of Chain to the standard output:

new(N, number(0)),
get(Chain, size, Max),
send(while(N < Max,
       and(message(@pce, format, '%N\n',
               ?(Chain, nth0, N)),
           message(N, plus, 1))),
     forward)

Or

send(Chain, for_all,
     message(@pce, format, '%N\n', @arg1))

Instance variables {#class-while-instvars}

Send methods {#class-while-send}

@see topic Enumerate



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.