Using the Continue Statement in JavaScript

Using the continue statement in JavaScript

Like the break statement, the continue statement is used to stop the execution of the loop. However, the continue statement does not exit the loop; it executes the condition for the next iteration. If the loop has any statements after the continue statement, then those statements are executed.

Demo

  1. Let’s create a document called continueStatement.html.

  2. Write the following code,
    <!DOCTYPE HTML>
    <HTML>
      <HEAD></HEAD>
      <BODY>
        <TITLE>Using the continue statement</TITLE>
        <H1>Using the continue statement.</H1>
        <SCRIPT type="text/javascript">
          var count = 0;
          while (count < 10)
            ( < /BODY> < /HTML>
            }
            ++count;
          if ((count % 2 == 0)) continue;
          else document.write("count=" + count + " < BR / > ");
              document.write("While loop exited"):
        </SCRIPT>
  3. Execute the script by opening the file in the web browser. If you are using Internet Explorer, click on “Allow Blocked Content” to allow the script to execute, and if you are using Mozilla Firefox, click on allow “ActiveX Controls.”

Thanks for reading the blog.

Next Recommended Reading Using Break Statement in JavaScript