title: How can we ensure that a while loop would not be an infinite loop?
body: <p>This is a method where I am using the while loop. I strongly suspect that an infinite loop is possible. How to check and eliminate that?</p>
  
  <p>I am using two while loops here. Sould I totally dismantle the while loop?</p>
  
  <pre><code>public class ReferenceListSaveHandler
  {
  public PublishReferenceListUpdates populateResponse(SearchQueryResponse pSearchQueryResponse,SearchQueryResponse pListResponse, ObjectFactory objFactory)         throws IOException, ParserConfigurationException, SAXException,SipException, Exception
      {
          ReferenceDataProcessor lRefPro = new ReferenceDataProcessor();
          PublishReferenceListUpdates lResponse = null;
          Record listRecord = null;
          ReferenceDataListItemListType lReferenceDataListItemListType = objFactory
              .createReferenceDataListItemListType();
          ReferenceDataListType lReferenceDataListType = null;
          ReferenceDataListItemType lReferenceDataListItemType = null;
          boolean ifSynonym = false;
          String lRowIdObject = null;
          final int lRowIdLength = 14;
  
          if (refListItemItr.hasNext())
          {
              Record record = (Record)refListItemItr.next();
              boolean continueProcessing = true;
              boolean lastRecord = false;
              while (continueProcessing)
              { // first use of while loop
                  if (refListItemItr.hasNext() || lastRecord)
                  {
                      continueProcessing = true;
                      lastRecord = false;
                  }
                  else
                  {
                      continueProcessing = false;
                  }
  
                  if (continueProcessing)
                  {
                      lSynonymListType = objFactory
                          .createSynonymListType();
  
                      Field itemLSIDField = record
                          .getField(ReferenceDataConstants.FIELD_COMPOUND_ASSET_ID);
  
                      if (itemLSIDField == null)
                      {
                          continue;
                      }
                      else
                      {
                          currentItemLSID = itemLSIDField
                              .getStringValue().trim();
                      }
                      lReferenceDataListItemType = objFactory
                          .createReferenceDataListItemType();
                      lReferenceDataListItemType = setListDetails(record,
                          lReferenceDataListItemType,
                          lId, lName, objFactory);
  
  
                      while (refListItemItr.hasNext()
                             &amp;&amp; continueProcessing)
                      {  // second use of while loop
                          SynonymType lSynonymType = null;
                          if (continueProcessing)
                          {
                              if (lSynonymType != null)
                                  lSynonymListType.getSynonym().add(lSynonymType);
                          }
                      }
                      continueProcessing = true;
                  }
              }//while loop
          }
      }
  }
  </code></pre>
  
  <p>Please help.</p>