title: Google Apps Script function calls within for loop ISSUE
body: <p>I have a main function that calls a second function which contains a for loop that calls a third function multiple times. The third function returns a value to the for loop each iteration and that value is pushed to an empty array which is declared outside the for loop. The third function also calls two other functions to get this done. ALL functions work perfectly well on their own. </p>
  
  <p>Ultimately, when the for loop in the second function is finished, the second function returns the populated array back to the first function. 
  Unfortunately, no matter what i do, the second function only iterates the for loop once and then somehow breaks out of it on its own and still returns the single value that the third function was able to return. </p>
  
  <p>The for loop does call the third function successfully the one time and gets the return value, and pushes it to the array, which then does get successfully returned back to the first function. Why is the for loop in the second function only able to call the third function once and then seems to break out of itself automatically of it's own accord?</p>
  
  <p>I have tested with three very simple functions, and i have no issues with the for loop breaking out after the first iteration.</p>
  
  <p><strong>within first function, calling second function 
  and sending two predefined parameters:</strong></p>
  
  <pre><code>    var flavsCosts = calcFlavCost(batchNum,chosenFlavors);
  </code></pre>
  
  <p><strong>second function:</strong></p>
  
  <pre><code>    function calcFlavCost(batchNum,chosenFlavors) {
  
      var allBatchFlavsCosts = [];
  
        for (i=0;i&lt;chosenFlavors.length;i++)  // chosenFlavors.length &gt;= 2
        {
        /* 
          iterates thru chosenFlavors, and creates unique
          variables thisFlav and thisNumKegs each iteration,
          then calls third function: 
        */
        var thisFlavCost = getFlavCost(thisFlav,thisNumKegs);   
        allBatchFlavsCosts.push(thisFlavCost);  
        }
      return allBatchFlavsCosts;
      }
  </code></pre>
  
  <p><strong>third function:</strong></p>
  
  <pre><code>    function getFlavCost(thisFlav,thisNumKegs) {
      // calls a function getRecipe(), which returns 2d array
      // calls a function getUnitCosts(), which returns simple array
      // executes a for loop for some math stuff
      // returns total cost to function 2
  
      return materialCosts;
      }
  
  </code></pre>