Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda