title: Loop with Deferred objects and promises
body: <p>I have the following code </p>
  
  <pre><code>    $.when(tableInsert("index.php/get/sync/riesgos", insert_riesgo, evalua.webdb.db, callback)).then(function(){
          update_records("riesgos");
          $.when(tableInsert("index.php/get/sync/estancias", insert_estancia, evalua.webdb.db, callback)).then(function(){
              update_records("estancias");
              $.when(tableInsert("index.php/get/sync/riesgosestancias", insert_riesgoestancia, evalua.webdb.db, callback)).then(function(){
                  update_records("riesgosestancias");
              });
          });
      });
  </code></pre>
  
  <p>I am trying to find how to integrate it inside of a for loop or a $.each loop, so that it waits for the promise to be done before the next iteration. At first it looks like three calls would be easier to be nested, but this is only a piece of code, the nested calls count 15 now!</p>