title: Nodejs wait for a for loop to finish with mysql query
body: <p>I have a sql query which I execute in nodejs with the node-mysql library.</p>
  
  <p>I want to run a for loop on the result of the query, like this:</p>
  
  <pre><code>sql.query(query, function(err, rows, field){
  if (err) throw err;
  for(var i = 0; i &lt; rows.length; i++) {
      do_something_complicated();
  }
  }
  </code></pre>
  
  <p>I tried using the async library and put the sql.query() in the first function and the rest of my code in the second function but it waits for the query to finish but not for the for loop.</p>
  
  <p>Can anyone help?</p>