Monday , June 21 2021
Home / Java / JAVA #17 – Jump Statement (break,continue and label) in Java

JAVA #17 – Jump Statement (break,continue and label) in Java

The break Statement

The break statement has two forms: labeled and unlabeled. You saw the unlabeled form in the previous discussion of the switch statement. You can also use an unlabeled break to terminate a for, while, or do-while loop

 

package breakcountinue; // Break Statement with Label
public class Breakcountinue {
    public static void main(String[] args) {
        
        loop:
        for (int i = 0; i < 5; i++) {
            
             System.out.println("Ali");                             
             break loop;
             System.out.println("Ibad");         
             
        }
    }
    
}

 

package breakcountinue;
public class Breakcountinue {
    public static void main(String[] args) {
       
        for (int i = 0; i < 5; i++) {
            
             System.out.println("Ali");                             
             break;
             System.out.println("Ibad");         
             
        }
    }
    
}

 

 

The continue Statement

The continue statement skips the current iteration of a for, while , or do-while loop. The unlabeled form skips to the end of the innermost loop’s body and evaluates the boolean expression that controls the loop.

package breakcountinue;
public class Breakcountinue { 
    public static void main(String[] args) {
       
        for (int i = 0; i < 5; i++) {
            
             System.out.println("Ali");                             
             continue;
             System.out.println("Ibad");         
             
        }
    }
    
}

 

About Faheem

An adaptable and responsible Software Engineer, who enjoys working with computers and the opportunity to learn new skills and work with new technologies is particularly attractive to me.

Check Also

JAVA #32 – Java application using SQL server (Part: 01)

  In this part we made the GUI front end of a Application.

Leave a Reply

Your email address will not be published.