Why are "continue" statements bad in JavaScript?

JavascriptWeb DevelopmentFront End Technology

The usage of “continue” statement makes the code difficult to understand. In most cases, the usage of continue would mean you have an insufficient condition in your loop. To avoid this, you can add it to the condition itself or use if in a loop.

But, “continue” is bad if it is used inconsistently or improperly, else it is a useful statement and saves a lot of memory and lines of code.

Example

Let’s see an example of continue statement

Live Demo

<html>
   <body>
      <script>
         var x = 1;
         document.write("Entering the loop<br /> ");
         while (x < 10) {
            x = x + 1;
            if (x == 5) {
               continue; // skip rest of the loop body
            }
            document.write( x + "<br />");
         }
         document.write("Exiting the loop!<br /> ");
      </script>
   </body>
</html>
raja
Published on 23-Jan-2018 13:50:03
Advertisements