是否可以延迟value
内的变量window.setTimeout
,并将超时的毫秒值设为我的time
变量?
var value = null;
var time = 5000;
for(var i = 0; i < 30; i++){
if(value === "a"){
console.log("You made it!");
} else {
console.log("You didn't make it!");
}
time = time - 100;
}
答案 0 :(得分:1)
是的,您可以使用setInterval()方法执行此操作:
clearInterval()
这里100毫秒是间隔
使用clearInterval(myVar);
停止时间:
myVar
这里int** n = new int*[N];
for (int i = 0; i < N; ++i){
int size;
cin >> size;
n[i] = new int[size];
for (int j = 0; j < size; ++j){
cin >> n[i][j];
}
}
是setInterval函数的变量名。
答案 1 :(得分:1)
您可以创建一个回调函数来执行此操作
var value = null;
var time = 5000;
var limit=30;
var i = 0;
function delay(limit, time, callback) {
loop();
function loop(){
if(value = "a")// it may be a comparison (you are assigning value).
{
setTimeout(function(){
i++;
if (i<=limit && time >= 0){
callback("callback after"+time);
callback("You made it!");
loop();
}
}, time)
}
else
{
callback("You didn't make it!");
}
time=time-100;
}
}
// Calling a callback function
delay(limit,time, function(callback){
console.log(callback);