Difference between Break and Continue Statement in JavaScript

vaishnavi mehrotra
1 min readFeb 28, 2021

--

Hii Everyone, I am Vaishnavi Mehrotra. I joined The Hacking School coding Bootcamp. The atmosphere is very good, My instructor Prashant is a very awesome and very excellent teacher. The hacking school coding Bootcamp is the best place to enhance your skills in Coding. I found myself very lucky to be part of this institution.

Break

The break statement is used to break the iteration or the discontinuation of the loop. If the defined condition is true, the break statement is executed in the loop or switch.

A break statement is used in various loops like for, while, do-while, foreach loop, and the switch case statement.

Syntax:

if (condition)
{
break;
}

Example:

for (var i = 1; i <= 5; i++) {
if (i === 3) {
console.log("Three");
break;
} else {
console.log(i);
}
}

Continue

The continue statements are used only to skip the iteration and move to the next iteration of the loop. If the defined condition is true, the continue statement is executed in the loop or switch.

A continue statement is also used in various loops like for, while, do-while, foreach loop, and the switch case statement.

Syntax:

if (condition)
{
continue;
}

Example:

for (var i = 1; i <= 5; i++) {
if (i === 3) {
continue;
} else {
console.log(i);
}
}

Summary

  1. The break statement will completely terminate the loop.
  2. The continue statement will skip the current iteration only.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response