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

79
Visualizações
Skipping repeated every 5th in line

I try to using continue in for loop to skip every 5th iteration. But, I just know how to write the continue in which just skip the first 5th. Not sure how I can implement the continue statement to make it work. The correct output should be:

1  is odd.
2  is even.
3  is odd.
4  is even.
6  is even.
7  is odd.
8  is even.
9  is odd.
11  is odd.
12  is even.
13  is odd.
14  is even.
16  is even.
17  is odd.
18  is even.
19  is odd.

Here is my code.

forwardOp(1,20)
function forwardOp(startIndex, endIndex){
    if (startIndex > endIndex){
        console.log("Start number cannot be less than End number.");
    }
    for (i = startIndex; i <= endIndex; i++){
        if (i === 5){continue;}
        if (i % 2 ==0){
            console.log (i," is even.")
        }else {
            console.log (i, " is odd.")
        }
    }
}
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Same as module 2

if (i % 5==0){
            console.log (i," is divisible by 5.")
        }
about 4 years ago · Juan Pablo Isaza Relatório

0

You must use i % 5 == 0.

Here is the fixed code to make it easy:

forwardOp(1,20)
function forwardOp(startIndex, endIndex){
    if (startIndex > endIndex){
        console.log("Start number cannot be less than End number.");
    }
    for (i = startIndex; i <= endIndex; i++){
        if (i % 5 == 0){
            // 'i' is divisible by 5
        }
        if (i % 2 ==0){
            console.log (i," is even.")
        } else {
            console.log (i, " is odd.")
        }
    }
}
about 4 years ago · Juan Pablo Isaza Relatório

0

The line if (i === 5){continue;} means that the 5th line gets skipped over. If you want to skip every 5th line you should use modulo: if (i%5 == 0){continue;}

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