The following code is work as the following
while loop>> bring a and b values>> settimeout>> check the value by if-condition>> continue it true, else break;
This code with settimeout and is not working:
var number = 0;
start_position: while (true) {
setTimeout(function() {
console.log("Anything you want to print");
var a = Math.random();
var b = Math.random();
}, 1000)
number++;
if (a > b) continue start_position;
break;
}
This code without settimeout and is work just fine:
var number = 0;
start_position: while (true) {
console.log("Anything you want to print");
var a = Math.random();
var b = Math.random();
number++;
if (a > b) continue start_position;
break;
}
This is another way I tried too:
var counter = 0;
var i = setInterval(function(){
var a=Math.random();
var b=Math.random();
console.log("a:",a);
console.log("b:",b);
counter++;
if(a<b || a=b) {
clearInterval(i);
}
}, 200);
Please, any suggestions?
setInterval, not a loop.