Hey I have been trying to figure this out for a while now but my script is behaving unexpectedly. I can not understand the execution flow of the following script.
My Script:
$scope.getEmployeeQualifications = function () {
    if ($scope.displayEmpQualification) {
        $scope.displayEmpQualification = false;
    }
    else {
        $scope.loading = true;
        $scope.displayEmpQualification = true;
        $http.get('/ERPProduct/api/CEmployeeQualificationsApi/' + this.employee.cEmployeeId + '/').success(function (data) {
            $scope.employeeQualifications = [];
            for (var item = 0; item < data.length; item++)
            {
                if (data[item].contId) {
                    $http.get('/ERPProduct/api/CountriesApi/' + data[item].contId + '/').success(function (test) {
                        data[item].contId = test.contName;
                    });
                }
                if (data[item].cityId) {
                    $http.get('/ERPProduct/api/CitiesApi/' + data[item].cityId + '/').success(function (test) {
                        alert("First Test");
                        data[item].cityId = test.cityName;
                    });
                }
            }
            alert("Test");
            $scope.employeeQualifications = data;
            $scope.loading = false;
        }).error(function (data) {
            $scope.error = "An Error has occured while Saving office! " + data;
            $scope.loading = false;
        });
    }
};
Expected Behaviour:
I expect the above script to first display the alert("First Test"); and complete the loop and when it has completed the loop it should display the alert("Test");.
Actual Behaviour:
The script is not behaving as it should but rather displaying the alert("Test"); and then when I press Okay then it continues to execute the loop. 
My Question
As I have described above that I can not understand the above script behaviour.
- What is the execution flow of the above script?
- What are the reasons for that flow ?
- Am I making any mistakes in the above script that are causing unexpected behaviour and execution flow of the above script?
Thanks.
