TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Java

Java break Statement

Overview

In this post, we will discuss the Java break statement. Sometimes we may come across situations where we want to skip loops or terminate the loop.

We can use the break statement in all the loops in Java. When a break statement is executed, the loop is terminated and the control is transferred to the next statement outside the loop.

break statement

We can use the break statement to terminate the loop immediately. The control of the program reaches to the next statement after the loop.

Let’s see with an example.

public class BreakDemo {

 public static void main(String[] args) {
 // TODO Auto-generated method stub
 for (int i = 1; i < 100; i++) {
 if (i == 7) {
 break; // The loop will terminate when i reaches 7
 }
 System.out.println("i=" +i);
 } 
 }
}

 

 

 

In the case of nested loops, the break statement terminates the innermost loop, and control jumps to the next outer loop that surrounds in the depth.

—

Java Tutorials

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/in/java/

Related Posts

Download Greenfoot Windows

Java /

Download & Install Greenfoot on Windows

Java /

Java Static Code Analysis

Java /

Java Testing Tools

Java /

Handle Multiple Exceptions in Java

Exceptions_In_Java

Java /

Exceptions in Java Programs

‹ Java continue Statement› Java Bitwise Operators

Recent Posts

  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • RAPTOR Editions
  • Flowgorithm Conditional Breakpoint Statement
  • Flowgorithm Read Numbers from File Example
  • Search Text File Flowchart Example
  • Flowgorithm Turtle Graphics Symbols
  • Draw Circle using Flowgorithm Turtle
  • Draw Parallel Lines using Flowgorithm Graphics

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version