next up previous

12.6.3 While

The while function is provided to allow simple looping. Its use is similar to that of the if function.

Syntax

(while <expression> [do]
   <action>*)

Again, all predicate functions are available for use in while. Any number of allowable actions may be placed inside the while block, including if...then...else or additional while structures. The test is performed prior to the first execution of the loop. The actions within the while loop are executed until <expression> evaluates to the symbol FALSE. The while may optionally include the symbol do after the condition and before the first action. The break and return functions can be used to terminate the loop prematurely. The return value of this function is FALSE unless the return function is used to terminate the loop.

Example

(defrule open-valves
   (valves-open-through ?v)
   =>
   (while (> ?v 0)
      (printout t "Valve " ?v " is open" crlf)
      (bind ?v (- ?v 1))))


next up previous