title: Javascript for loop until error
body: <p>I want to create a loop that will continue until it reaches an error then continues on... </p>
  
  <pre><code>for (var m = 0; m != 'Error'; m++)
  </code></pre>
  
  <p>If I push the iterations too high, it will throw a "TypeError", which indicates that the limit has been reached.  This for loop exists inside another loop which needs to continue and not crash the script, just discontinue the loop.</p>
  
  <p>Thanks!</p>
  
  <p>EDIT CODE FOLLOWS:</p>
  
  <pre><code>for (var i = 0; i &lt; 100; i++) {
    var xml = fs.readFileSync('./Filename-' + (i + 100) + '.xml', 'utf-8');
    var level1 = bb(xml)
    for (var m = 0;; m++) {
      try {
       if (level1.data.level2[m].product.code == '7472558') {
          console.log(level1.data.level2[m].product.code);
          total++}
      }
      catch (e) {
       break;
      }
    }
  console.log(total)
  }
  </code></pre>