SHARE

Break and Continue are two reserved keywords in JavaScript that help us when trying to ‘get out’ of a loop, and we’ll cover both in this tutorial.

Break, as the name suggests, breaks out of a loop at any given point, and Continue just tells the loop to ‘skip’ this particular iteration and carries on with the next one.

As always, if you have any questions, ask away :).

SUBSCRIBE TO CHANNEL – https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg?sub_confirmation=1

========== JavaScript for Beginners Playlist ==========

https://www.youtube.com/playlist?list=PL4cUxeGkcC9i9Ae2D9Ee1RvylH38dKuET

========== CSS for Beginners Playlist ==========

https://www.youtube.com/playlist?list=PL4cUxeGkcC9gQeDH6xYhmO-db2mhoTSrT

========== HTML for Beginners Playlist ==========

https://www.youtube.com/playlist?list=PL4cUxeGkcC9ibZ2TSBaGGNrgh4ZgYE6Cc

========== The Net Ninja ============

For more front-end development tutorials & to black-belt your coding skills, head over to – https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg or http://thenetninja.co.uk

========== Social Links ==========

Twitter – @TheNetNinja – https://twitter.com/thenetninjauk

8 COMMENTS

  1. It's easy to understand all these Javascript rules but hard to understand the practical use of all these codes in web development. it would be so kind of you if you explain the actual use of these codes at the same time.

  2. If anyone is still confused by what "continue" does, copy and execute this code in console and it will be clearer.

    var myLoop = document.getElementsByTagName("p");

    for (i = 1; i <= myLoop.length; i++) {

    if (i === 5 || i === 3) {
    console.log("Restart loop when equal " + i);
    continue;
    }
    console.log("this is number " + i);

    if(i === 7) {
    break;
    }
    }
    console.log("loop ended successfully");

  3. Hey mate, quick question for "while, for, break & continue" – can you give an example on where can I possibly use this codes on a certain project? I.e. how or why would I use this when creating a website or something else. JS is daunting seriously. Lol.

LEAVE A REPLY

Please enter your comment!
Please enter your name here