title: Angular.JS loop keeps running while a service call inside the loop is waiting for promise
body: <p>"AddDistance" is an insert to DB function,
  the problem is that hash[k][2] value jumps forward with the loop while "distance"(the service promise) is still waiting, and as result i insert wrong row to my DB.</p>
  
  <p>how do i hold the loop from jumping to the next object before "AddDistance()" ran, should i use Q$, While, .then()?</p>
  
  <p>i tried the above but failed, probably didn't do it correctly.</p>
  
  <p>Please advise...</p>
  
  <pre><code> for (var k in hash)
      {
           GoogleMaps(hash[k][0], hash[k][1], function (x) {
              var distance = x.rows[0].elements[0].distance.value;
              distance = parseInt(distance / 1000);
              AddDistance({ CityID1: hash[k][2], CityID2: $scope.CompanyCity.Id, DistanceKM: distance });
              console.log(distance);
              //return distance;
  
          });
  
      }
  </code></pre>