Conversation

Your input fuels progress! Share your tips or experiences on prioritizing mental wellness at work. Let's inspire change together!

Join the discussion and share your insights now!

Comments 0

Sharpen your coding skills—try JavaScript challenges on TOOLX now!

advertisement

Break and Continue Statement in JavaScript

break and continue in js


1. break Statement:

The break statement can be used with decision-making statements, such as switch-case statements, and loop constructs, such as for and while loops. It is denoted by the break keyword. It is used to exit the loop without evaluating the specified condition. Then, the control is passed to the next statement immediately after the loop.

The use of the break statement in JavaScript

for (let i = 0; i < 10; i++) {
  if (i === 5) {
    break
  }
  console.log(i);
}


2. continue Statement:

The continue statement is mostly used in loop constructs. The continue keyword denotes the continue statement. It terminates the current execution of the loop and continues with the next repetition by returning the control to the beginning of the loop. The continue statement does not terminate the loop entirely but terminates the current execution.

The use of the continue statement in JavaScript

for (let i = 0; i < 10; i++) {
  if (i === 5) {
    continue;
  }
  console.log(i);
}


JavaScript break statement continue statement break and continue statement in javascript break statement in js continue statement in js break and continue

advertisement