Teachnique
      CourseRoadmaps
      Login

      OverviewPlacementSyntaxHello WorldConsole.log()CommentsVariableslet StatementConstantsData TypesType ConversionsStrict ModeReserved Keywords

      OperatorsArithmetic OperatorsComparison OperatorsLogical OperatorsBitwise OperatorsAssignment OperatorsConditional Operatorstypeof OperatorNullish Coalescing OperatorDelete OperatorComma OperatorGrouping OperatorYield OperatorSpread OperatorExponentiation OperatorOperator Precedence

      If...ElseWhile LoopsFor LoopFor...in LoopFor...of LoopLoop ControlBreak StatementContinue StatementSwitch CaseUser Defined Iterators

      FunctionsFunction ExpressionsFunction ParametersDefault ParametersFunction() ConstructorFunction HoistingArrow FunctionsFunction InvocationFunction call() MethodFunction apply() MethodFunction bind() MethodClosuresVariable ScopeGlobal VariablesSmart Function Parameters

      NumberBooleanStringsArraysDateMathRegExpSymbolSetsWeakSetMapsWeakMapIterablesReflectTypedArrayTempate LiteralsTagged Templates

      Objects OverviewClassesObject PropertiesObject MethodsStatic MethodsDisplay ObjectsObject AccessorsObject ConstructorsNative PrototypesES5 Object MethodsEncapsulationInheritanceAbstractionPolymorphismDestructuring AssignmentObject DestructuringArray DestructuringNested DestructuringOptional ChainingGlobal ObjectMixinsProxies

      HistoryVersionsES5ES6ECMAScript 2016ECMAScript 2017ECMAScript 2018ECMAScript 2019ECMAScript 2020ECMAScript 2021ECMAScript 2022

      CookiesCookie AttributesDeleting Cookies

      Browser Object ModelWindow ObjectDocument ObjectScreen ObjectHistory ObjectNavigator ObjectLocation ObjectConsole Object

      Web APIHistory APIStorage APIForms APIWorker APIFetch APIGeolocation API

      EventsDOM Events

      Feedback

      Submit request if you have any questions.

      Course
      Continue Statement

      JavaScript Tutorial

      This JavaScript tutorial is crafted for beginners to introduce them to the basics and advanced concepts of JavaScript. By the end of this guide, you'll reach a proficiency level that sets the stage for further growth. Aimed at empowering you to progress towards becoming a world-class software developer, this tutorial paves the way for a successful career in web development and beyond.

      Continue Statement

      The continue statement in JavaScript is used to skip the current iteration of a loop and continue with the next iteration. It is often used in conjunction with an if statement to check for a condition and skip the iteration if the condition is met.
      The JavaScript continue statement tells the interpreter to immediately start the next iteration of the loop and skip the remaining code block. When a continue statement is encountered, the program flow moves to the loop check expression immediately and if the condition remains true, then it starts the next iteration, otherwise the control comes out of the loop.

      Syntax

      The syntax of continue statement in JavaScript is as follows
      continue;
      OR
      continue label;
      We can use the continue statement inside the loops like for loop, while loop, do…while loop, etc.
      We will learn to use the ‘continue’ statement with the ‘label’ statement in the upcoming chapter.

      Continue statement with for loop

      The example below uses the continue statement with the for loop. In the loop, when the value of the x is 3, it will execute the continue statement to skip the current iteration and move to the next iteration.
      In the output, you can see that the loop doesn’t print 3.

      Example

      <html>
      <head>
      <title> JavaScript - Continue statement </title>
      </head>
      <body>
      <p id = "output"> </p>
      <script>
      let output = document.getElementById("output");
      output.innerHTML += "Entering the loop. <br /> ";
      for (let x = 1; x < 5; x++) {
      if (x == 3) {
      continue; // skip rest of the loop body
      }
      output.innerHTML += x + "<br />";
      }
      output.innerHTML += "Exiting the loop!<br /> ";
      </script>
      </body>
      </html>

      Output

      Entering the loop.
      1
      2
      4
      Exiting the loop!

      Continue statement with while loop

      We used the while loop with the continue statement in the example below. In each iteration of the while loop, we increment the x's value by 1. If the value of the x is equal to 2 or 3, it skips the current iteration and moves to the next iteration.
      In the output, you can see that the code doesn’t print 2 or 3.

      Example

      <html>
      <head>
      <title> JavaScript - Continue statement </title>
      </head>
      <body>
      <p id = "output"> </p>
      <script>
      let output = document.getElementById("output");
      var x = 1;
      output.innerHTML += "Entering the loop. <br /> ";
      while (x < 5) {
      x = x + 1;
      if (x == 2 || x == 3) {
      continue; // skip rest of the loop body
      }
      output.innerHTML += x + "<br />";
      }
      output.innerHTML += "Exiting the loop!<br /> ";
      </script>
      </body>
      </html>

      Output

      Entering the loop.
      4
      5
      Exiting the loop!

      Continue statement with the nested loop

      You can use the continue statement with nested loops and skip the iteration of the parent loop or child loop.

      Example

      The parent loop traverses the 1 to 5 elements in the code below. In the parent loop, we used the continue statement to skip the iteration when the value of x is 2 or 3. Also, we have defined the nested loop. In the nested loop, we skip the loop iteration when the value of y is 3.
      In the output, you can observe the value of x and y. You won’t see 2 or 3 values for x and 3 for y.
      <html>
      <head>
      <title> JavaScript - Continue statement </title>
      </head>
      <body>
      <p id = "output"> </p>
      <script>
      let output = document.getElementById("output");
      output.innerHTML += "Entering the loop. <br /> ";
      for (let x = 1; x < 5; x++) {
      if (x == 2 || x == 3) {
      continue; // skip rest of the loop body
      }
      for (let y = 1; y < 5; y++) {
      if (y == 3) {
      continue;
      }
      output.innerHTML += x + " - " + y + "<br />";
      }
      }
      output.innerHTML += "Exiting the loop!<br /> ";
      </script>
      </body>
      </html>

      Output

      Entering the loop.
      1 - 1
      1 - 2
      1 - 4
      4 - 1
      4 - 2
      4 - 4
      Exiting the loop!