title: In angular function not waiting to complete first function execution
body: <p>my function didnt wait to complete earlier function execution and it is completing.</p>
  
  <p>I have my code is that i am doing some thing wrong:</p>
  
  <pre><code>$scope.abc1 = function(){
   var arrayJson = [{'name':'max','age':'12'},{'name':'tax','age':'16'}]
   for(var i=0; i&lt;arratJson.length;i++){
    var getAddress = $scope.xyz(arratJson[i].name);
      }
    $scope.createBody();
  
   };
   $scope.createBody = function(){
   //some more code here
   };
   $scope.xyz = function(name){
      $http({
              method: 'GET',
              url: 'rest/address',
              type:'json',
              headers:{'action':'single','name':name},  
              }).success(function(response){
               return response;
              }).error(function(response){
  
              });
     };
  </code></pre>
  
  <p>so in this it is not waiting to get address instead of it moving down so how to wait finishing for loop and then call different function.
  createBody function called before the $scope.xyz() function returns the value how to wait until loop finishes</p>