This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Single for loop (i) | |
// i loop | |
loop(0, function(i){return i<10;}, function(i){return i+1;}, | |
function(i, next){ | |
// looping. | |
console.log(i); | |
next(); | |
}, | |
function(i){ console.log("all done."); } | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loop(init, fnCondition, fnUpdate, fnRun, fnDone){ | |
var index = 0; | |
index = (init.constructor.name === "function")?init():init; | |
function next(){ | |
index = fnUpdate(index); | |
if(fnCondition(index)){ | |
setTimeout(function(){ | |
fnRun(index, next); | |
}, 0); | |
}else{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var i = 0; | |
var j = 0; | |
var k = 0; | |
var m = 0; | |
function forloop1(){ | |
if(i<5){ | |
j = 0; | |
forloop2(); | |
}else{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(var i=0; i<5; i++){ | |
for(var j=0; j<5; j++){ | |
for(var k=0; k<5; k++){ | |
for(var m=0; m<5; m++){ | |
console.log(i,j,k,m); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var i = 0; | |
var j = 0; | |
function forloop1(){ | |
if(i<10){ | |
j = 0; | |
forloop2(); | |
}else{ | |
console.log("all done"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var i = 0; | |
function forloop1(){ | |
if(i<10){ | |
(function(){ | |
var j = 0; | |
function forloop2(){ | |
if(j<10){ | |
console.log(i,j); | |
j++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(var i=0; i<10; i++){ | |
for(var j=0; j<10; j++){ | |
console.log(i,j); | |
} | |
} | |
console.log("all done."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var i = 0; | |
function forloop(){ | |
if(i<5){ | |
$.getJSON('/data'+i+'.json', function(data) { | |
console.log("yay! Data"+i+" is ready!"); | |
i++; | |
forloop(); | |
}); | |
}else{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.getJSON('/data0.json', function(data) { | |
console.log("yay! Data0 is ready!"); | |
// ok, now use that to get the next piece of data. | |
$.getJSON('/data1.json', function(data) { | |
console.log("yay! Data1 is ready!"); | |
// ok, now use that to get the next piece of data. | |
$.getJSON('/data2.json', function(data) { | |
console.log("yay! Data2 is ready!"); | |
// ok, now use that to get the next piece of data. | |
$.getJSON('/data3.json', function(data) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.getJSON('/data0.json', function(data) { | |
console.log("yay! Data0 is ready!"); | |
}); |
NewerOlder