/* */ Click to Join Live Class with Shankar sir Call 9798158723

Break Statement in java


It is one of the most important statements is the break statement in java and let’s see how to use the java break label.break is used to break or terminate a loop whenever we want.Just type break; after the statement after which you want to break the loop.


Syntex :-

for(.....)
{
......
if(error1)
break;
.....
} break;

Q.) W.A.P of to Print 1 to 10 no. ?
    class Test {
    public static void main(String[] args) {
      
        // for loop
        for (int i = 1; i <= 10; ++i) {

            // if the value of i is 5 the loop terminates  
            if (i == 5) {
                break;
            }      
            System.out.println(i);
        }   
    }
} 
    
Output
1
2
3
4