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

126
Vistas
make loop run endlesly starting from 1 when it reaches max

I have this loop which runs like I want it every 5 seconds updating, but I want it to start from beginning when it reaches 20 I tried if statement, but I guess I do something wrong,

I want I to be 1 when it is 20 without breaking the loop I tried

thank you

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As per the description and comments, the requirement is the loop should execute infinitely without breaking and should count from 1 -> 20 -> 1.

For this, following code can be used:

function task(profileIndex) {
    setTimeout(
        () => {
            currentPage = profileIndex + 1; // For 0 it would be 1, for 19 it would be 20
            // Following line would take care of infinite loop
            task((profileIndex + 1) % 20); // % 20 will take care of resetting it to 0 when (profileIndex + 1) is 20. Otherwise, it won't do any manipulation.
        },
        500 // After every 500ms, the page would be updated.
    )
}

task(0)
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