 <pre><code>while( someOuterLoopCondition ) { var m = 0; var innerLoopOK = true; while( innerLoopOK ) { try { // your original inner-loop body goes here } catch e { innerLoopOK = false; } m++; } } </code></pre> <p>Or:</p> <pre><code>while( someOuterLoopCondition ) { for( var m = 0; m &lt; upperBound; m++ ) { try { // your original inner-loop body goes here } catch e { break; // breaks inner-loop only } } } </code></pre>