Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
Appscript: how to repeat a while loop?

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%10) == 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

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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());
  }
}
about 4 years ago · Juan Pablo Isaza Report

0

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);
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!