title: How to break out of the for loop in nodejs
body: <p>Well the problem is simple, I am using a query within the for loop and and I want to get out of the for loop if I get the count less than 15, otherwise increase the assigned. But I can't be able to use the break statement and the loop will continue to execute even after the first callback.</p>
  
  <pre><code>  for (var i = 0; i &lt; test; i++) {
  
                  var sql = "SELECT count(*) as count FROM `tb_members` WHERE `assigned`=?";
                  connection.query(sql, [assigned], function (err, response) {
  
                      if (response[0].count &lt; 15) {
  
                          callback(assigned);
  
                      }
                      else {
                          ++assigned;
  
                          if (i == test - 1) {
                              callback(0);
                          }
                      }
                  });
              }
  </code></pre>