Occasionally, you need rules to be re-evaluated and re-fired (if satisfied). This scenario requires the Corticon rule engine to make multiple passes through the same Rulesheet. This behavior is called advanced inferencing, and to enable it in Rulesheet execution, you must set Rulesheet processing mode to Advanced Inferencing by selecting Rulesheet > Processing Mode > Advanced Inferencing from the Studio menubar, as shown:

Figure 1. Selecting Advanced Inferencing Processing Mode for a Rulesheet

We emphasize it here with an orange highlight to the immediate left of the Conditions header.

If the rule engine is permitted to loop through the rules, the following events occur:

Given a value of A as the initial data, the condition in rule 1 will be satisfied and the rule will fireirclsetting the value to B. The second rule's condition is then satisfied, so the value will advance (or be reset) to C, and so on, until the value is once again B after the fourth rule fires. Up to this point, the rule engine is exhibiting standard, optimized inferencing behavior.

Here is the new part: the value (state) changed since the second rule last fired, so the rule engine will re-evaluate the condition, and, finding it satisfied, will fire the second rule again, advancing the value to C. The third rule will also be re-evaluated and re-fired, advancing the value to D, and so on. This sequence is illustrated in the following figure.

Figure 2. Loop Iterations

Here is the key to understanding looping: when a looping processing mode is enabled, rules are continually re-evaluated and re-fired in a sequence determined by their dependency network as long as the data state changed since their last firing. Once the data state no longer changes, looping ceases.

Notice that the last column of the table indicates the number of loop iterations. The first loop does not begin until rule 2 fires for the second time. The first time through the rules (steps 1-4) does not count as the first loop iteration because the loop does not actually start until step 5.