Essential JavaScript

Going Further

Continuing a Loop

We used the break keyword earlier to break out of a loop entirely.

It is also possible to simply continue to the next iteration of the loop:

let i = 0; while (i < 10) { i++; if (i % 2 === 0) { continue; } console.log(i); }

In this example, any time i is an even number the loop will continue.

The continue statement causes the current iteration of the loop to stop. If the loop is still running, the next iteration will start.

Learning Goals

  • I can use continue to end the current iteration of a loop

Code Editor

Click "Run Code" to execute your JavaScript in a secure sandbox and see the output below.

Console Output

// Console output will appear here...

0 output lines