The format of the WHILE External function is:
WHILE(Run@, Test@, Move@, Startup@, Initialise@)
The function returns a logical value after a loop has run to completion.
In normal programming terms, the operation of a WHILE loop may be visualised as:
a := initial_value; WHILE a < 10 do begin a := a + 3; end;
There is considerable machinery implicit here, testing, varying the value of a, asserting a sequence and performing a conditional jump. In a knowledge network, a := a + 3 is not a valid statement as the variable "a" can have only one value at a time, and in changing its value, the old value is lost. The WHILE Function is provided to handle the operation of a WHILE loop. The function must be used in conjunction with the GATE or GETPUT functions, which do retain the old value of a variable. The parameters of the WHILE Function are:
In operation, searching comes in on link 1, the value of the function. What happens next is:
There are three tricks here.
Setting Initialise@ to TRUE for the first cycle allows the GATE or GETPUT Functions to provide an initial value.
Resetting Run@ to TRUE at the start of each loop will kill the old values, as Run@
controls the
logical environment of at least the GATE functions.
Searching for Move@ allows the GATE functions to become active, and store the incremented
values of variables for use in the next cycle.
The operation of the function will not appear obvious to someone used to computer
programming, where a WHILE is made out of a conditional jump back to a previous operation,
and the phase of operations is implicit in the sequence. This WHILE operates more like an
electrical relay or logic microcircuit, where connections have to be made to its inputs
and outputs for it to operate correctly.
WHILE is also provided as a Drawn Function.