continue Statement in JavaScript

The JavaScript continue statement or keyword is used to skip the execution of statement(s) for current iteration of the current loop. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>
   
   <script>
      for(let i=0; i<=5; i++)
      {
         if(i==3)
            continue;
         console.log(i);
      }
   </script>
   
</body>
</html>

The snapshot given below shows the sample output produced by above JavaScript example on continue statement:

continue statement in javascript

As you can see from the above example, when the value of i becomes 3, then the continue statement gets executed to skip the remaining execution of statement(s) for current iteration.

JavaScript continue Syntax

The syntax of continue statement in JavaScript, is:

continue;

Note - The break Vs. continue in JavaScript is described in its separate tutorial.

Note - Only the statement(s) after the continue statement will be skipped, for of course current iteration of the current loop. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>
   
   <script>
      for(let i=0; i<=5; i++)
      {
         console.log(i);
         if(i==3)
            continue;
         console.log(i);
      }
   </script>
   
</body>
</html>

The sample output of this example is shown in the following snapshot:

javascript continue statement

In above example, when the value of i becomes 3, then the above two statements was executed, whereas the below two statements (the two statements after the continue statement) was skipped.

JavaScript Online Test


« Previous Tutorial Next Tutorial »