Reputation: 24061
I have a loop:
for (var language in locales) {
if(language == 'en') //go on to next language and do not do code below
I wish to prevent code inside the for from executing in certain conditions.
I've tried break;
but this stops the entire loop from continuing on to the next language.
How can I prevent code from executing below the if statement but still maintain a loop?
Upvotes: 2
Views: 225
Reputation: 288000
Alternatively to continue
, you can just use an if
statement:
for (var language in locales) if(language !== 'en') {
// ...
}
Upvotes: 2
Reputation: 181
Use-continue
for (var language in locales) {
if(language == 'en')
continue;
statement;
}
Upvotes: 2
Reputation: 10083
You need to use continue
for skipping current iteration of a loop and continue with the next iteration.
Upvotes: 7