Javascript
JavaScript Fundamentals -- Looping in JavaScript

Skipping Passes Through Loops

Mute
Current Time 0:00
/
Duration Time 0:00
Loaded: 0%
Progress: 0%
Stream TypeLIVE
Remaining Time -0:00
 
PRO

There may be times when you want to skip one pass through a loop. To do that, you can use the continue keyword:


for( let i = 0; i < 5; i++) {
  if (i === 3) {
      continue;
  }
    console.log(i);
}

In that example, we say that if our i variable is 3, we want to skip that pass of the loop. So, that loop will print four numbers to the console: 0, 1, 2, and 4.

If you have any questions about using continue, you can also read about it in this blog post.

 

I finished! On to the next chapter