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 ==========
========== CSS for Beginners Playlist ==========
========== HTML for Beginners Playlist ==========
========== 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
Original source
22 responses to “JavaScript Tutorial For Beginners #18 – Break & Continue”
Great tut my phone blurs every youtube video which sucks.
Sound effects are great! Great tutorial, thx for posting!
You should make these courses for UDEMY
Listening to that "WAAHHH" every single time without forwarding the video xD
Great job man, you're da MVP!
I used continue in my loop and Airbnb eslint told me I'm not allowed to use it. Went on the Internet and read that it's bad for readability of your code and you shouldn't use it.
How would you replace it? Is there a trick that doesn't make your code less readable and skips one iteration or should you write your code in a totally different way from the start with this in mind to omit "continue" usage?
fantastic help, got my head around it seeing it rather than reading it! Cheers bro
Awesome content👍🇷🇺🇺🇸🤝
Ivan brought me here. Thanks for sharing your video it's very helpful.
I need some help in building break and continue javascript
I want to write a code where there is like 5 switch toggles
If toggle1 is ON, audio1 will be played, then continue to toggle2
if toggle2 is OFF, break and skip to toggle3
if toggle3 is ON, audio3 will be played
until toggle5
How can i write such code, please help
I love your channel. Thanks you!
Ivan sent me.
Please stop the extra loud music. Otherwise these are very good lessons
Hi what if i had 9 links and i wanted the first 3 to be green and the next 3 links to be blue and the last to be yellow but alternate when links are added. how can i achive this Thanks sir
where can i get these codes
my console doesnt work welp
Such a simple yet highly satisfying video intro
Brushing up on JS really fast and I never actually understood this until now. Thanks ninja
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.
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");
Where are you programming your code?
If we use continue, does it keep endlessly looping too, unless there is break?
Great videos! Thanks for posting!
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.