MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Loop Control: break, continue0%
Study Materials
JavaScript for BeginnersProgress 0%
1.1What is JavaScript?1.2How JavaScript Works in Browser1.3Setting up Environment: VSCode, Live Server
5.1For Loop5.2While and Do-While Loops5.3Loop Control: break, continue
HomeTutorialsJavaScript for BeginnersLoop Control: break, continue
String Basics

Loop Control: break, continue

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

Loop Control: break and continue

When executing loops, standard sequential execution isn't always enough. You may want to exit a loop early when a searched item is found, or skip the current iteration when encountering invalid data. JavaScript provides break and continue for granular loop control.


1. The break Statement: Emergency Exit

The break statement immediately terminates the entire loop and jumps execution to the first statement following the loop:

1Iteration 1 ---> Iteration 2 ---> [ break encountered! ]
2 |
3 v
4 [ Jump OUT of loop completely ]

Real-World Example: Linear Search

1const studentIds = [101, 204, 305, 409, 512, 630];
2const target = 305;
3let foundIndex = -1;
4 
5for (let i = 0; i < studentIds.length; i++) {
6 if (studentIds[i] === target) {
7 foundIndex = i;
8 console.log(`Target ${target} found at index ${i}!`);
9 break; // Stop looping! No need to check the remaining elements!
10 }
11}

Without break, the loop would uselessly continue checking the remaining elements, wasting CPU cycles!


2. The continue Statement: Skip to Next Iteration

The continue statement does not terminate the loop. Instead, it skips the rest of the current iteration and jumps immediately to the next iteration (evaluating the increment and condition):

1Iteration 1 ---> Iteration 2 [ continue! ] ---> Iteration 3
2 |
3 +--> (Skips rest of body, proceeds to next cycle!)

Real-World Example: Filtering Bad Data

1const transactions = [100, -20, 500, 0, -50, 300];
2let totalDeposits = 0;
3 
4for (let i = 0; i < transactions.length; i++) {
5 // Skip withdrawals or zero amounts:
6 if (transactions[i] <= 0) {
7 continue; // Skip directly to next transaction!
8 }
9 
10 totalDeposits += transactions[i];
11}
12 
13console.log(`Total valid deposits: ₹${totalDeposits}`); // ₹900

3. Summary: break vs continue

StatementWhat it doesLoop Status
breakTerminates loop immediatelyExits the loop entirely
continueSkips remainder of current stepContinues with next step

4. Labeled Statements (Advanced)

When working with nested loops, a standard break only exits the innermost loop. To break out of an outer loop from within an inner loop, use a label:

1outerLoop: for (let row = 0; row < 3; row++) {
2 for (let col = 0; col < 3; col++) {
3 if (row === 1 && col === 1) {
4 console.log("Treasure found! Breaking outer loop.");
5 break outerLoop; // Exits BOTH loops!
6 }
7 console.log(`Scanning cell (${row}, ${col})`);
8 }
9}

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What is the effect of encountering a break statement inside a loop?
Question 2
What is the effect of encountering a continue statement inside a loop?
Question 3
In a loop from 1 to 10, what numbers are printed by:
JavaScriptCode Snippet
1for (let i = 1; i <= 5; i++) {
2 if (i === 3) continue;
3 console.log(i);
4}
Question 4
When a break is executed inside an inner loop of a nested loop structure without labels, what happens?
Question 5
Can break be used inside a switch statement?
Next Lesson

String Basics

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
While and Do-While LoopsString Basics

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Beginners with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext