Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

Java Break


Java Break

In Java, the break statement is used primarily to exit or terminate the loop in which it is used. It is often employed within loops (such as for, while, or do-while) and switch statements. Here's how break works in different contexts:


  1. Loop Control:

  2.              for (int i = 0; i < 10; i++) {
                    if (i == 5) {
                        break; // Exit the loop when i equals 5
                    }
                    System.out.println(i);
                 }
                
               

    In this example, when i becomes 5, the break statement causes the loop to terminate immediately.



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

Zava