DEV Community

zhou-yg
zhou-yg

Posted on

What will happened when writing switch case with "break" in a for loop

demonstration code:
javascript
const arr = [1,2,3];
for (const n of arr) {
switch (n) {
case 1: console.log(n); break;
default: console.log(n); break;
}
}

Amazing! the "break" keyword won't break the for loop

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay