The format of the FORNEST function is:
The function returns a logical value after a loop has run to completion.
In normal programming terms, the operation of nested for loops may be visualised as
follows:
FOR a := 1 to 10 do FORNEST({{a,1,10},{b,2,7}},Test@,... FOR b := 2 to 7 do c := a + b; Test@ EQV LOGSTATE(c)
In a knowledge network, the individual FOR operators can be separate state machines, or they may be combined into a nested form, as here. There will be instances where the form of the statement being driven is
c := c + a + b
The FORNEST function may be used in conjunction with the LATCH or
GETPUT functions, which will initialise and then retain the old
value of a variable.
The parameters of the FORNEST Function are:
List% -Source of variables to be cycled, and values. Test@ -Returns value of test, "executes" loop. Move@ -Logical input, controls moving of values through GATE. Startup@ - Logical input, starts loop if TRUE, skip if FALSE. Initialise@ - Logical output, set TRUE on first cycle, then FALSE.
The values in the list can be of the following form
Note the double bracing for simple loop indexes, necessary so loops can be nested.
In operation, searching comes in on link 1, the value of the function. What happens next
is:
The logic connected to the Test@ pin can be made to return FALSE or ERROR if an
inconsistent result is found, so the FORNEST loop can be used to search for and save all
valid values, or used to find a maximum by having part of the test be a check for higher
than some previous value.
If a variable in the list of variables being set has a value already set, it will be
trodden on.
Related Functions
GATE | |
GETPUT | |
WHILE |
See FORNEST & GETPUT