title: Drools JBOSS rule Nested IF's
body: <p>I am a newbie with Jboss Rule. I have gone through the documentation but I fail to find the approach to begin writing rule for following code sample.</p>
  <pre><code>For each User code in the list 
  {
      If User code = ‘11’ 
      {
          If User code ‘17’ present in the group 
          {
              Add letter id 1
          }
          Else If User code ‘18’ present in the group 
          {
              Add letter id 2
          }
      }
      Else 
      {
          Add letter id 3 which is the letter need to be sent for code 11
      }
  }
  </code></pre>
  <p><strong>EDIT:</strong></p>
  <p>So far this is what i can develop for the user case discussed above.</p>
  <ol>
  <li>I am inserting (List of <code>UserDetailVo</code>) to the drools session.</li>
  <li>Object (<code>UserDetailVo</code>) contains (List of <code>UserInfoVo</code>). Every <code>UserInfoVo</code> contains a code.</li>
  </ol>
  <p>Now I want to iterate over the (List of <code>UserInfoVo</code>) and update (<code>letterId</code>) to every (<code>UserDetailVo</code>) as i am trying to do below.</p>
  <p><strong>Case1 : when codeList has 110,121</strong></p>
  <pre><code>rule &quot;USER LETTER GROUPING 110,121&quot; 
  salience 300
  no-loop true
  
      when
          userDetailVo : UserDetailVo ()
          UserInfoVo(code==&quot;110&quot;) from userDetailVo.codeList
          UserInfoVo(code==&quot;121&quot;) from userDetailVo.codeList
      then
          userDetailVo.addLetterId(1);
          //modify(trrDetailRequestVo)
  end
      
  </code></pre>
  <p><strong>Case2 : when codeList has 110,127</strong></p>
  <pre><code>rule &quot;USER LETTER GROUPING 110,127&quot; 
          salience 300
          no-loop true
      
              when
                  userDetailVo : UserDetailVo ()
                  UserInfoVo(code==&quot;110&quot;) from userDetailVo.codeList
                  UserInfoVo(code==&quot;127&quot;) from userDetailVo.codeList
              then
                  userDetailVo.addLetterId(2);
                  //modify(trrDetailRequestVo)
          end
  </code></pre>
  <p><strong>Case3 : when codeList has only 110</strong></p>
  <pre><code>rule &quot;USER LETTER GROUPING 110&quot; 
      salience 300
      no-loop true
      
          when
              userDetailVo : UserDetailVo (this.letterID.size() == 0) // Checking size of the list
              UserInfoVo(code==&quot;110&quot;) from userDetailVo.codeList
          then
              userDetailVo.addLetterId(3);
              //modify(trrDetailRequestVo)
      end
  </code></pre>
  <p>Issues that I am facing is if I user modify/update at the end of rule. It goes into an infinite loop. If I remove modify/update, in case 3 though list size if greater than 0 still rule is fired.</p>