title: Javascript breaking a for loop inside a callback function
body: <p>I have code like the following:</p>
  
  <pre><code>function test(obj) {
  
      if(//some conditon) {
          obj.onload();
      }else{
          obj.onerror();
      }
  }
  
  
  for(var i=0;i&lt;4;i++){   
  
      test({
          onload:function(e){          
              //some code to run
          },
          onerror:function(e){
              break;
          }
  
  
      });
  }
  </code></pre>
  
  <p>The gist is the test() function is a function to make an XHR request (it is actually an API of the Appcelerator Titanium platform so I have no control over it) and I'm looping something to call the test function.  I need to break the loop on the onerror function, but I get an error saying the break is not inside a loop or switch statement.  How can I rewrite this?</p>