1.184 class while

An instance of class while executes it's while<-body until it's while<-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))

1.184.1 Instance variables

while <-> body: code*
The body (statement). If @nil, the condition is executed until it fails.
while <-> condition: code
The condition. Note that an always true statement can be created as new(and) and an always false as new(or).

1.184.2 Send methods

while ->initialise: condition=code, statement=code*
Create from condition and statement (while<-body).
while ->_execute:
Execute the while<-body while the while<-condition holds.
See also
topic Enumerate