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.


Let’s see an example of continue statement

Live Demo

         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 /> ");
Updated on 08-Jan-2020 10:20:39