This is my while loop as it stands at the moment:
function rowcount()
{
var token = getAccessToken();
var module = "sHistory";
var rows = 0;
var go = true;
var i = 1;
var data;
while (go) {
//Utilities.sleep(10000)
data = getRecordsByPage(i,200,token,module);
if (Number(data.info.count) < 200) {
go = false;
};
if ((i) == 0) {
go = false;
}
rows = Number(rows) Number(data.info.count);
i ;
Logger.log("rowcount " rows)
}
return rows
}
My question is how do I use a for loop to repeat the while loop 93 times with a timer of 10 seconds per passing?
Can you demonstrate by giving a sample of for loop code? I have been sitting on this for days, I have tried a for loop, but I think I am doing it wrong, please assist, I created a new function that I am trying to repeat the while function.
function repeatloop()
{
for(i=rowcount(); i <= 10; i )
{
Utilities.sleep(10000)
Logger.log(i)
i
}
}
I just need the above sorted out for my script to be completed
CodePudding user response:
i
should be initialized to 0
. Call i
only once.
function repeatloop() {
for (let i = 0; i < 10; i ) {
Utilities.sleep(10000);
console.log(i);
console.log(rowcount());
}
}
CodePudding user response:
You can use setInterval
.
Something like this:
function repeatLoop() {
let i = 0;
if (typeof repeatLoop.prototype.counter === 'undefined') {
repeatLoop.prototype.counter = 0;
}
const intervalInstance = setInterval(() => {
if (i > 10) {
clearInterval(intervalInstance);
} else {
console.log(repeatLoop.prototype.counter);
i ;
repeatLoop.prototype.counter ;
}
}, 10000);
}