0

Can anybody help me to explain continue, because I don't really understand. and why this thing work only with 0 and 1? creating loop for even numbers

for (let i = 2; i <= 10; i++) {

if(i % 2 == 1) continue;

alert(i);
}

Thank U:)

somebody help me, I'm really confused hehehe

callMeZu
  • 3
  • 1
  • Does this answer your question? [Using continue Statement in JavaScript](https://stackoverflow.com/questions/70936416/using-continue-statement-in-javascript) – Janis Jansen Aug 15 '23 at 06:26
  • Does this answer your question? [C# loop - break vs. continue](https://stackoverflow.com/questions/6414/c-sharp-loop-break-vs-continue) – Frederik Hoeft Aug 15 '23 at 09:55

1 Answers1

0

The continue statement in JavaScript is like a skip button for loops. Imagine you're counting from 2 to 10. If you find a number that's odd (like 3 or 5), you press the skip button. This means you won't pay attention to that odd number and instead move on to the next one. So, with your code, you're counting from 2 to 10, but only showing the numbers that aren't odd. And by the way, 0 and 1 aren't odd or even – they're kind of special.

Mohamed Mostafa
  • 520
  • 2
  • 10