JavaScript Continue Statement

The continue statement is used inside the loop. In continue statement if a specified condition occurs, then it skips the current iteration and execute to the next iterations of the loop. The basic syntax of Continue statement is as follows :
  continue;
Or
  continue [ label_name ]; 
Where :

  • The continue keyword skip the current iteration of the loop.
  • The label keyword is optional, it is basically transfer control to the specified label_name.

Now lets see an example of Continue statement :
<!DOCTYPE html>
<html>
<head>
  <title>Continue Statement</title>
</head>
<body>
  <script>
    brk = "<br/>";
    var x = 0;
    while (x < 10) {
      x++;
      if(x == 6) {
        continue;
      }
      document.write(x, brk);
    }
  </script>
</body>
</html>
Output :


As we can see in the above example when x is equal to 6, then the rest of the code will skipped and the loop will goes to next iteration.


Next Topic :