something.some((test) => {
if(a == 0) {
if(b == 0) {
continue;
}
}
});
Can I skip one loop with this continue
?
The WebStorm reports continue outside of loop statement
.
something.some((test) => {
if(a == 0) {
if(b == 0) {
continue;
}
}
});
Can I skip one loop with this continue
?
The WebStorm reports continue outside of loop statement
.
You can't use continue
, but you can use return
to skip the rest of the statements in your handler and continue with the next item:
something.some((test) => {
if(a == 0) {
if(b == 0) {
return;
}
// X...
}
// Y...
});
If the logic hits the return
for an entry, then neither the code at X
or Y
above will be executed for that entry.
If you want the equivalent of break
(stop the "loop" entirely) within a some
callback, return true
.
Side note: That usage of some
looks suspect. Normally, you only use some
if you return a value from the some
callback (telling some
whether to continue). Probably 90% (waves hands) of the time you also use some
's return value to know whether the loop was stopped early or continued. If you never return anything from the callback, forEach
(or a for-of
loop) would be the idiomatic choice, not some
.