24.11.2014 Views

flex Expert System Toolkit - LPIS

flex Expert System Toolkit - LPIS

flex Expert System Toolkit - LPIS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

7. Knowledge Specification Language 79<br />

For Loops<br />

and the loan of Customer is paid<br />

do remove_instance( Customer )<br />

end while .<br />

Simple for loops repeat the given directives for every solution found to a<br />

given condition.<br />

The basic format of a for loop is:<br />

for condition(s)<br />

do directive(s)<br />

end for<br />

Examples<br />

The following action could be used to print the names of all the instances<br />

of employee, adding a new line between each (nl/0 is a built-in Prolog<br />

predicate).<br />

action print_employees ;<br />

do for every Name is some instance of employee<br />

do write( Name ) and nl<br />

end for .<br />

Extended For Loops<br />

Extended for loops repeat the given directives while an index steps from<br />

one limit to another.<br />

The basic format of a for-from-to-step loop is:<br />

for counter<br />

from expression1<br />

to expression2<br />

step expression3<br />

do directive(s)<br />

end for<br />

If the step expression3 is omitted, the counter will be incremented<br />

in steps of 1.<br />

Example<br />

The following action steps through values for X from -20 to 20 in steps of 5,<br />

and for every value of X steps through the values of Y from -20 to 20 in<br />

steps of 1, and for each Y value prints the value of X times Y.<br />

<strong>flex</strong> toolkit

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!