I've got a function called runUpdates that I pass an array of JSON objects to. This function looks through the objects and has if statements to decide what kind of update it is and which direction it should take to process that update. In some situations the update has an animation tied to it. I want to use jQuery's animate to animate these but I want it to wait for the animation to finish before it proceeds to the next step.

My program looks something like this-

```
runUpdates(updates) {
    for(i = 0; i < updates.length; i++) {
        update = updates[i];
        if(update.type = "blabla") {
            //do stuff
        } else {
            //do other stuff
            if(update.animations) {
                for(k = 0; k < animations.length; k++) {
                    //do jquery animate AND wait for animation to finish before proceeding
                }
            }
        }
    }
}

```

But the script will continue running even after the animation has started. Is there a simple way to fix this or am I going to need to reinvent the loop with function calls?