3.3 General Principles for Writing Loops

The general principle in writing procedural Aspen SCM Expert System code is to retain truth at all times. With loops this means that we should aim to ensure that we prove the predicate so that the rule ends TRUE. We must do this if we wish to pass values back as return arguments in the predicate or if we have set “Error on Unknown”.

There are two types of loop:

As a general principle, IN loops are to be preferred to WHILE loops because:

  • there is no upper limit on the number of iterations, so the code will execute as it is written;

  • IN loops finish cleanly, even when they are FALSE, and can then execute an OR clause. By contrast, WHILE loops always BREAK, which transfers control to an outer loop (or ends the rule if there isn’t one).

Set against this, WHILE loops have the advantage that:

  • they are easy to use where one wants to loop an arbitrary number of times.


Back                                Next

Comments