Good Day,
I have a while loop that iterates 5 times and loops through 200 rows every iteration. Is there a way to have the while loop keep going until it reaches its last row? This is for a row count.
Here is the current while loop I have for the row count so far:
function testMe(a) {
if(a == 5) {
return JSON.parse('{"info":{"count":"3"}}');
}
else {
return JSON.parse('{"info":{"count":"200"}}');
}
}
function rowcount ()
{
var rows = 0;
var go = true;
var i = 1;
var data;
while (go) {
data = testMe(i);
if (Number(data.info.count) < 200) {
go = false;
};
rows = Number(rows) + Number(data.info.count);
i++;
}
Logger.log(rows);
}
Use nested loops, such that the inner loop runs while the outer loop holds, and then breaks out of the outer loop when the last time row has been completed. Your current loop should be your inner loop, the outer loop should be like
while (rows <= 200){
while (go) {
data = testMe(i);
if (Number(data.info.count) < 200) {
go = false;
};
rows = Number(rows) + Number(data.info.count);
i++;
}
}