Using break and continue in Loops in Javascript


Exit a loop or skip iterations.

Source Code

for (let i = 0; i < 10; i++) {
  if (i === 5) break; // Exit loop when i is 5
  if (i % 2 === 0) continue; // Skip the rest of the loop if i is even
  console.log(i); // 1, 3
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments