title: Why is statements of invoking .then automatically excluded from the for loop
body: <p>I tried to loop the elements in an array using for-loop, and then screen eligible elements by two .then statements which are called within the loop body(see the code below), when I ran the code, I noticed that the two .then statements within loop body are not invoked until for-loop end even I defined them within loop body, it means only the last element is passed into .then statement, not screen each element as expected.
  please advise how the subsequent .then statements can be executed in each loop. thanks.</p>
  
  <pre><code>//get all of opportunity list
  commonFunction.getAllTextByXpath(dealWorkspace.opportunityNameXPath).then(function (inactiveOpptyList) {
      //to identify the oppty with permission 'Admin' and status 'On Hold' 
      for (var j = 0; j &lt; inactiveOpptyList.length; j++) {
           var inactiveOpptyName = inactiveOpptyList[j];
  
           //get permission of the opportunity
           dealWorkspace.getPermissionOppty(inactiveOpptyName).then(function (permission)     {
               if (permission === 'Admin') {
                  //get status of the opportunity
                  dealWorkspace.getStatusByOppty(inactiveOpptyName).then(function (status) {
  
                      //take action of Delete opportunity with cancel option
                      if (status === 'On Hold') {
                         inactiveOppty.deleteOppty(inactiveOpptyName, 'Cancel');
                      }
                  });
               }
           });
      }
  });
  </code></pre>
  
  <p>Two .then functions used in the script above:</p>
  
  <pre><code>//get the permission with oppName
  dealWorkspace.prototype.getPermissionOppty = function(oppyName) {
  
  return element(by.xpath("//span[contains(text(),'"+oppyName+"')]/parent::*/parent::*/following-sibling::td[@class='permission-td capitalize ng-binding']")).getText();
  };
  
  //get the status with oppName
  dealWorkspace.prototype.getStatusByOppty = function(oppyName) {
  
  return element(by.xpath("//span[contains(text(),'"+oppyName+"')]/parent::*/parent::*/following-sibling::td[@class='status-td capitalize ng-binding']")).getText();
  };
  </code></pre>