Skip to content

Instantly share code, notes, and snippets.

@acatl
Created October 23, 2013 18:21
Show Gist options
  • Save acatl/7123843 to your computer and use it in GitHub Desktop.
Save acatl/7123843 to your computer and use it in GitHub Desktop.
loop break
var la = new Array(500);
for (var i = 0; i < la.length; i++) {
la[i] = i;
}
var target = [];
var loop = function () {
var temp = la;
var slices = 50;
var timer = setInterval(function () {
var len=temp.length
for (var i=0;i < len;i++) {
if (i==slices) {
console.log("exit loop");
break;
}
target.push(temp[i]);
console.log(i);
}
temp = temp.slice(slices, -1);
if(temp.length==0){
console.log("exit timer", target, '-------', la);
clearInterval(timer);
}
},0);
}
loop();
console.log('outsite', la.length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment