Using break and continue in Loops in Javascript


Control loop execution with break and continue.

Source Code

for (let i = 0; i < 10; i++) {
  if (i === 5) {
    break; // Exits the loop
  }
  if (i % 2 === 0) {
    continue; // Skips the rest of the loop and continues with the next iteration
  }
  console.log(i); // 1, 3
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments