<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:p="urn:schemas-microsoft-com:office:powerpoint" xmlns:a="urn:schemas-microsoft-com:office:access" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns:b="urn:schemas-microsoft-com:office:publisher" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:odc="urn:schemas-microsoft-com:office:odc" xmlns:oa="urn:schemas-microsoft-com:office:activation" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:q="http://schemas.xmlsoap.org/soap/envelope/" xmlns:D="DAV:" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:ois="http://schemas.microsoft.com/sharepoint/soap/ois/" xmlns:dir="http://schemas.microsoft.com/sharepoint/soap/directory/" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" xmlns:udc="http://schemas.microsoft.com/data/udc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sub="http://schemas.microsoft.com/sharepoint/soap/2002/1/alerts/" xmlns:ec="http://www.w3.org/2001/04/xmlenc#" xmlns:sp="http://schemas.microsoft.com/sharepoint/" xmlns:sps="http://schemas.microsoft.com/sharepoint/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:udcxf="http://schemas.microsoft.com/data/udc/xmlfile" xmlns:wf="http://schemas.microsoft.com/sharepoint/soap/workflow/" xmlns:mver="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns:mrels="http://schemas.openxmlformats.org/package/2006/relationships" xmlns:ex12t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ex12m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:Z="urn:schemas-microsoft-com:" xmlns:st="&#1;" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Correct. <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>

<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] <b>On Behalf Of </b>Bryan Hansen<br>
<b>Sent:</b> Monday, November 03, 2008 9:37 AM<br>
<b>To:</b> Rules Users List<br>
<b>Subject:</b> Re: [rules-users] no-loop usage question<o:p></o:p></span></p>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal style='margin-bottom:12.0pt'>I think I follow you now. If I
was a little smarter with my conditional statements to NOT keep assigning YES
to something that is already set to YES then it would probably eliminate the
loop. In other words if I added more checks like the ==null that you pointed
out, I could (although I am not sure that they are bad) remove the no-loop
settings. Right?<br>
<br>
Thanks,<br>
<br>
Bryan<o:p></o:p></p>

<div>

<p class=MsoNormal>On Mon, Nov 3, 2008 at 9:17 AM, Joe White &lt;<a
href="mailto:Joe.White@recondotech.com">Joe.White@recondotech.com</a>&gt;
wrote:<o:p></o:p></p>

<div>

<div>

<p><span style='font-size:11.0pt'>You need no-loop on the rules because of the
call to &quot;modify(s)&quot; . Modify changes the&nbsp; fact in working memory
and the engine is automatically notified of the changes at the end of the
modify block. After modify the same rule could hit again as the conditions are
still true.</span><o:p></o:p></p>

<p><span style='font-size:11.0pt'>&nbsp;</span><o:p></o:p></p>

<p><span style='font-size:11.0pt'>The first rule doesn't need the no-loop it
because of the check &quot;</span>recommendPurchase == null&quot;<o:p></o:p></p>

<p>&nbsp;<o:p></o:p></p>

<p>Joe<o:p></o:p></p>

<p><span style='font-size:11.0pt;color:#1F497D'>&nbsp;</span><o:p></o:p></p>

<div style='border:none;border-top:solid windowtext 1.0pt;padding:3.0pt 0in 0in 0in;
border-color:-moz-use-text-color -moz-use-text-color'>

<p><b><span style='font-size:10.0pt'>From:</span></b><span style='font-size:
10.0pt'> <a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>
[mailto:<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>]
<b>On Behalf Of </b>Bryan Hansen<br>
<b>Sent:</b> Sunday, November 02, 2008 8:21 PM<br>
<b>To:</b> <a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<b>Subject:</b> [rules-users] no-loop usage question</span><o:p></o:p></p>

</div>

<div>

<div>

<p>&nbsp;<o:p></o:p></p>

<p>I have been reading through the documentation and trying some of the
tutorials and have a question about the no-loop attribute. <br>
<br>
Not really relevant to the post, but I figured I would mention it, I have been
following this post and updating it to use the current version of Drools. <a
href="http://www.onjava.com/pub/a/onjava/2005/08/03/drools.html?page=7"
target="_blank">http://www.onjava.com/pub/a/onjava/2005/08/03/drools.html?page=7</a>
<br>
<br>
I have written my rules as such:<br>
<br>
package org.drools.examples<br>
<br>
import org.drools.examples.StockOffer;<br>
<br>
rule PriceBelow100<br>
&nbsp;&nbsp;&nbsp; dialect &quot;java&quot; <br>
&nbsp;&nbsp;&nbsp; when<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s: StockOffer( stockPrice &lt; 100
&amp;&amp; recommendPurchase == null )<br>
&nbsp;&nbsp;&nbsp; then<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; modify( s ) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
setRecommendPurchase(StockOffer.YES)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
end<br>
<br>
rule NegativeStockPrice<br>
&nbsp;&nbsp;&nbsp; dialect &quot;java&quot; <br>
&nbsp;&nbsp;&nbsp; no-loop true<br>
&nbsp;&nbsp;&nbsp; when<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s: StockOffer( stockPrice &lt; 0 )<br>
&nbsp;&nbsp;&nbsp; then<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; modify( s ) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
setRecommendPurchase(StockOffer.NO)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
end&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
<br>
rule DontBuyXYZStock<br>
&nbsp;&nbsp;&nbsp; dialect &quot;java&quot; <br>
&nbsp;&nbsp;&nbsp; no-loop true<br>
&nbsp;&nbsp;&nbsp; when<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s: StockOffer(stockName ==
&quot;XYZ&quot; &amp;&amp; stockPrice &lt; 10 )<br>
&nbsp;&nbsp;&nbsp; then<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; modify( s ) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
setRecommendPurchase(StockOffer.YES)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
end&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
<br>
rule BuyXYZStock<br>
&nbsp;&nbsp;&nbsp; dialect &quot;java&quot; <br>
&nbsp;&nbsp;&nbsp; no-loop true<br>
&nbsp;&nbsp;&nbsp; when<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s: StockOffer(stockName ==
&quot;XYZ&quot; &amp;&amp; stockPrice &gt; 10 )<br>
&nbsp;&nbsp;&nbsp; then<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; modify( s ) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
setRecommendPurchase(StockOffer.NO)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
end&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
<br>
<br>
<br>
My question is, why do I have to put no-loop on every rule (except for the
first). After the first time through the rules, it shouldn't be modifying to
where the rules would fire it again. Am I doing something wrong with how my
rules are written? My sample data is this:<br>
<br>
package org.drools.examples;<br>
<br>
import org.drools.examples.BusinessLayer;<br>
import org.drools.examples.StockOffer;<br>
<br>
import junit.framework.TestCase;<br>
<br>
/*<br>
&nbsp;* JUnit test for the business rules in the <br>
&nbsp;* application.<br>
&nbsp;* <br>
&nbsp;* This also acts a 'simulator' for the business <br>
&nbsp;* rules - allowing us to specify the inputs,<br>
&nbsp;* examine the outputs and see if they match our <br>
&nbsp;* expectations before letting the code loose in&nbsp; <br>
&nbsp;* the real world.<br>
&nbsp;*/<br>
public class BusinessRuleTest extends TestCase {<br>
&nbsp;&nbsp;&nbsp; /**<br>
&nbsp;&nbsp;&nbsp; &nbsp;* Tests the purchase of a stock<br>
&nbsp;&nbsp;&nbsp; &nbsp;*/<br>
&nbsp;&nbsp;&nbsp; public void testStockBuy() throws Exception {<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Create a Stock with simulated values<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; StockOffer testOffer = new StockOffer();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
testOffer.setStockName(&quot;MEGACORP&quot;);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOffer.setStockPrice(22);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOffer.setStockQuantity(1000);<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Run the rules on it<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
BusinessLayer.evaluateStockPurchase(testOffer);<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Is it what we expected?<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
assertTrue(testOffer.getRecommendPurchase() != null);<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
assertTrue(&quot;YES&quot;.equals(testOffer.getRecommendPurchase()));<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; /**<br>
&nbsp;&nbsp;&nbsp; &nbsp;* Tests the purchase of a stock makes sure the system
will not accept<br>
&nbsp;&nbsp;&nbsp; &nbsp;* negative numbers.<br>
&nbsp;&nbsp;&nbsp; &nbsp;*/<br>
&nbsp;&nbsp;&nbsp; public void testNegativeStockBuy() throws Exception {<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Create a Stock with our simulated
values<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; StockOffer testOffer = new StockOffer();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
testOffer.setStockName(&quot;MEGACORP&quot;);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOffer.setStockPrice(-22);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOffer.setStockQuantity(1000);<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Run the rules on it<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
BusinessLayer.evaluateStockPurchase(testOffer);<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Is it what we expected?<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
assertTrue(&quot;NO&quot;.equals(testOffer.getRecommendPurchase()));<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; /**<br>
&nbsp;&nbsp;&nbsp; &nbsp;* Makes sure the system will buy stocks of XYZ corp
only if it really cheap<br>
&nbsp;&nbsp;&nbsp; &nbsp;*/<br>
&nbsp;&nbsp;&nbsp; public void testXYZStockBuy() throws Exception {<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Create a Stock with our simulated
values<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; StockOffer testOfferLow = new
StockOffer();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; StockOffer testOfferHigh = new
StockOffer();<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
testOfferLow.setStockName(&quot;XYZ&quot;);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOfferLow.setStockPrice(9);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOfferLow.setStockQuantity(1000);<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
testOfferHigh.setStockName(&quot;XYZ&quot;);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOfferHigh.setStockPrice(11);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; testOfferHigh.setStockQuantity(1000);<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // Run the rules on it and test<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
BusinessLayer.evaluateStockPurchase(testOfferLow);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
assertTrue(&quot;YES&quot;.equals(testOfferLow.getRecommendPurchase()));<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
BusinessLayer.evaluateStockPurchase(testOfferHigh);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
assertTrue(&quot;NO&quot;.equals(testOfferHigh.getRecommendPurchase()));<br>
&nbsp;&nbsp;&nbsp; }<br>
}<br>
<br>
<br>
I can post up all the code if this isn't enough to answer the question.<br>
<br>
Thanks!<o:p></o:p></p>

</div>

</div>

</div>

</div>

<p class=MsoNormal style='margin-bottom:12.0pt'><br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><o:p></o:p></p>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

</body>

</html>