title: how to delete all records excluding 0th record in array index
body: <p>As per the code I don't want to delete 0th record and delete rest of the record. But it is deleting all the records!</p>
  
  <p>Kindly assist where I am making the mistake.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>list&lt;account&gt; scope = [Select Id,(Select id,CreatedDate,ebMobile__FileType__c,ebMobile__Account__c from Files__r order by CreatedDate DESC) from account where id in ('0016D00000444','0016D000000ugO')]; 
          Set&lt;Id&gt;OldIds = new Set&lt;Id&gt;();
          Set&lt;Id&gt;newIds = new Set&lt;Id&gt;();
          Set&lt;Id&gt; rIds = new Set&lt;Id&gt;();
          Set&lt;Id&gt; rrIds = new Set&lt;Id&gt;();
          list&lt;File__c&gt; listmemb = new list&lt;File__c&gt;();
          List&lt;File__c&gt; listmemb3 = new List&lt;File__c&gt;();
          List&lt;File__c&gt; listmemb4 = new List&lt;File__c&gt;();
          for(Account Acc : scope)
          {
              for(File__c fi : Acc.ebMobile__Files__r)
              {
                  listmemb = [select id,CreatedDate,ebMobile__FileType__c from File__c where id =: fi.id];
                  if(fi.ebMobile__Account__c != Null)
                  {
                      for(Integer i=0; i&lt;listmemb.size(); i++)
                      {
                          if(fi.ebMobile__FileType__c == 'Signature' &amp;&amp; i==0)
                          {
                              rIds.add(listmemb[0].id); // Exclude 0th record 
                          }
                          if(i&gt;0 &amp;&amp; listmemb[i].ebMobile__FileType__c == 'Signature' || i &gt; 0 &amp;&amp; listmemb[i].ebMobile__FileType__c != 'signature')
                          {
                              rrIds.add(listmemb[i].id); // Delete all record excluding 0th record
                          }
                          if(fi.ebMobile__FileType__c != 'Signature')
                          {
                              OldIds.add(fi.id);  
                          }
                      }
                  }
              }
          }
          listmemb3 = [Select id,CreatedDate,ebMobile__FileType__c from File__c where id in : OldIds];
          listmemb4 = [Select id,CreatedDate,ebMobile__FileType__c from ebMobile__File__c where id in : rrIds];
          if(listmemb3.size() &gt; 0 &amp;&amp; listmemb4.size()&gt;0)
          {
              delete listmemb3;
              delete listmemb4;
          }
      }
  </code></pre>