You&#39;ll need 2 rules, one for truncating a key that does not match and another one for handling the match. If you have to handle absolute failure (not even &quot;a&quot; matches) you&#39;ll need a third rule and a more complex fact for storing the original and the truncated string.<br>
<br>These 2 rules are untested:<br><br>rule &quot;truncate when not found&quot;<br>when<br>    $s: String( length &gt; 0 )<br>    $m: Map( keySet not contains $s )<br>then<br>    retract( $s );<br>    insert( $s.substring( 0, $s.length() -1 );<br>
end<br><br>rule &quot;found&quot;<br>
when<br>
    $s: String()<br>
    $m: Map( keySet contains $s )<br>
then<br>
    System.out.println( &quot;key &quot; + $s + &quot; is in the Map&quot; );<br>
end<br>
<br>-W<br><br><div class="gmail_quote">On 4 October 2011 15:41, rahulkrishnan <span dir="ltr">&lt;<a href="mailto:rahulkrishnan8@gmail.com">rahulkrishnan8@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi<br>
 I want to match a string with the contents of hashmap. The process is like<br>
this.<br>
<br>
Let the string is &quot;abcd&quot;<br>
First it will search for abcd in the map<br>
if found i have to assign it to a variable else i has to remove the last<br>
alphabet (&quot;abc&quot;) and have to match with hashmap like is the process.<br>
<br>
My Problem is iam not able to do that iteration in when part<br>
What i have done is i will check the condition in when part if it matches<br>
the hashmap then it will exit. Else it will satisfies the condition(String<br>
not matching any of hashmap contents) and goes in then and update the string<br>
by removing the last alphabet and loops .<br>
<br>
rule &quot;somerule&quot;<br>
no-loop false<br>
when<br>
      condition for checking that hashmap  has no key of String s and<br>
s.length&gt;0<br>
then<br>
      modify the String s by removing last alphabet<br>
end<br>
<br>
<br>
is there any option to do the looping in the when part itself<br>
<font color="#888888"><br>
<br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Looping-in-When-part-tp3393236p3393236.html" target="_blank">http://drools.46999.n3.nabble.com/Looping-in-When-part-tp3393236p3393236.html</a><br>
Sent from the Drools: User forum mailing list archive at Nabble.com.<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><br>
</font></blockquote></div><br>