I've been reading JavaScript: The good parts. Theres a section: The Bad Parts. This is straight from the book:
continue Statement
The continue statement jumps to the top of the loop. I have never seen a piece of code that was not improved by refactoring it to remove the continue statement.
So my question is, is there ever a situation continue is required?
There are strong opinions on both sides, wether continue is useful or not. But it is never required. You can always find a way around it, if you want.
In my experience, the continue statement is useful if a condition in a loop is met, and you don't want to execute the rest of the code in the loop on that iteration. The reason why you'll get mixed opinions on its usefulness is that many will argue there are better ways to rewrite your code so you don't have to use it. In my opinion that argument is strictly for readability purposes.
I have never used continue in javascript because most of the javascript I write is simple DOM manipulation. However, I have used continue in various Python programs, and it can be useful (as mentioned above) to skip over the loop under certain conditions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With