<div>Using a fact as a guard to block alternatives is tricky. For one thing, you cannot use a single &quot;global&quot; fact. (When would you reset this fact to the initial state so that the whole mechanism can work again for the next fact set to be processed by this rule set?) So, you might consider inserting a flag fact along with one of the facts playing the key role in all of the conditions. But what if the participating facts change, and this &quot;if set&quot; should be activated again? How would you reset or recreate the flag fact?</div>

<div> </div>
<div>Also, the precedence implied by the ordering of the else branches would have to be expressed in the rules, using salience.<br> </div>
<div>So, the solution Greg has outlined is the one to pursue. As a general rule, keep in mind that</div>
<div> </div>
<div>  if( cond ){</div>
<div>      ...;</div>
<div>  } else {</div>
<div>     assert( ! cond );</div>
<div>     ...;</div>
<div>  }</div>
<div> </div>
<div>and</div>
<div> </div>
<div>  if( cond1){ if( cond2 ){ assert( cond1 &amp;&amp; cond2 );...;</div>
<div> </div>
<div>Thus, you can collect the precondition for each if branch that is to become a consequence of a rule, and the corresponding precondition is to be implemented as the left hand side.</div>
<div> </div>
<div>-W</div>
<div> </div>
<div> </div>
<div> </div>
<div><br> </div>
<div><span class="gmail_quote">On 6/16/09, <b class="gmail_sendername">Greg Barton</b> &lt;<a href="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><br>Note to drools devs: I didn&#39;t put the original poster up to this. :)<br><br>Globals should be considered immutable, so shouldn&#39;t be used in this way. You could do it with an object asserted in working memory, though.<br>
<br>Just as good, though, you can use this kind of pattern to replicate else logic:<br><br>rule &quot;EverythingMatches&quot;<br>when<br>Condition0<br>Condition1<br>Condition2<br>then<br>...<br>end<br><br>rule &quot;ElseAtCondition2&quot;<br>
when<br>Condition0<br>Condition1<br>!Condition2<br>then<br>...<br>end<br><br>rule &quot;ElseAtCondition1&quot;<br>when<br>Condition0<br>!Condition1<br>then<br>...<br>end<br><br>rule &quot;ElseAtCondition0&quot;<br>when<br>
!Condition0<br>then<br>...<br>end<br><br>--- On Mon, 6/15/09, Scott Reed &lt;<a href="mailto:sreed@avacoda.com">sreed@avacoda.com</a>&gt; wrote:<br><br>&gt; From: Scott Reed &lt;<a href="mailto:sreed@avacoda.com">sreed@avacoda.com</a>&gt;<br>
&gt; Subject: Re: [rules-users] Help -- Conditional Logic in DRL<br>&gt; To: &quot;Rules Users List&quot; &lt;<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>&gt;<br>&gt; Date: Monday, June 15, 2009, 10:19 PM<br>
&gt; Looks like 5 rules with a global flag<br>&gt; might work:<br>&gt;<br>&gt; global boolean flag = false;<br>&gt;<br>&gt; rule &quot;name1&quot;<br>&gt; when<br>&gt;   (condition1 == true )<br>&gt;   (flag == false)<br>
&gt; then<br>&gt;   consequence1();<br>&gt;   flag = true;<br>&gt; end<br>&gt;<br>&gt; ...<br>&gt;<br>&gt; rule &quot;name5&quot;<br>&gt; when<br>&gt;   (condition5 == true )<br>&gt;   (flag == false)<br>&gt; then<br>&gt;   consequence5();<br>
&gt;   flag = true;<br>&gt; end<br>&gt;<br>&gt; Does that work for you?<br>&gt;<br>&gt; Vishy [6/15/2009 11:06 PM] wrote:<br>&gt; &gt; Hi All,<br>&gt; &gt;<br>&gt; &gt; I am new to drools...and am trying to figure out as to<br>
&gt; how I can<br>&gt; &gt; represent the following logic in a DRL file.<br>&gt; &gt;<br>&gt; &gt; if (condition1) {<br>&gt; &gt;<br>&gt; &gt;   if (condition2) {<br>&gt; &gt;<br>&gt; &gt;   } else if (condition3) {<br>&gt; &gt;<br>
&gt; &gt;   } else if (condition 4) {<br>&gt; &gt;<br>&gt; &gt;   } else if (condition 5) {<br>&gt; &gt;<br>&gt; &gt;   }<br>&gt; &gt;<br>&gt; &gt; }<br>&gt; &gt;<br>&gt; &gt; In DSL, a typical rule is represented as follows:<br>
&gt; &gt;<br>&gt; &gt; rule &quot;name&quot;<br>&gt; &gt;<br>&gt; &gt; when<br>&gt; &gt;   condition is true<br>&gt; &gt; then<br>&gt; &gt;   consequence<br>&gt; &gt;<br>&gt; &gt; end<br>&gt; &gt;<br>&gt; &gt; How can I represent the above mentioned if - else<br>
&gt; logic in DSL? Or is<br>&gt; &gt; it not possible?<br>&gt; &gt;<br>&gt; &gt; If it is not, can you please suggest any alternative?<br>&gt; &gt;<br>&gt; &gt; Thanks much!!<br>&gt; &gt; _______________________________________________<br>
&gt; &gt; rules-users mailing list<br>&gt; &gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt; &gt;   <br>&gt; _______________________________________________<br>&gt; rules-users mailing list<br>&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br><br><br><br><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">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br>