PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Java · Theory

Java Break

← All stacks

Theory

22/270

Java Break

break immediately leaves the nearest loop or switch. In a loop, remaining rounds stop. In switch, later cases do not run.

A common pattern: search an array; when you find the value, break. No need to keep looping. continue is different: continue skips one round; break ends the loop.

In nested loops, plain break exits only the inner loop. If you expected both to stop, that is a mistake. Trace a loop that breaks at i == 3 and say exactly what prints.

Let's take this on the board with one tiny Main class — no extra files. Java Break — output: 1 then 2. When i is 3, break stops the loop — 4 and 5 never print. Start from main, go line by line, and stop at each print. That output is the proof for Break.

Exam tip

Trace break at i == 3. Say what prints.

Example

// Java Break
public class Main {
  public static void main(String[] args) {
    for (int i = 1; i <= 5; i++) {
      if (i == 3) {
        break;
      }
      System.out.println(i);
    }
  }
}

Java Break — output: 1 then 2. When i is 3, break stops the loop — 4 and 5 never print.

Short notes

  • Defbreak leaves the nearest loop or switch right now.
  • RuleIn nested loops, plain break exits only the inner loop.
  • Diffcontinue skips one round. break ends the loop.
  • UseStop early when the answer is found.

Questions

1

What does break do in a loop?

2

What does break do in switch?

3

Does break exit both nested loops?

4

How is continue different?

Previous← Java Do-While LoopNextJava Continue →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.