Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

200
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda