***Welcome to ashrafedu.blogspot.com ***This website is maintained by ASHRAF***

posts

    Jump Statements

    Jump statements are used to transfer the control of the program to the specific statements.

    Jump statements transfer the execution control to the other part of the program. 

    There are two types of jump statements in Java, i.e., break and continue.

    break statement:

    The break statement is used to break the current flow of the program and transfer the control to the next statement outside a loop or switch statement.

    The break statement cannot be used independently in the Java program, i.e., it can only be written inside the loop or switch statement. However, it breaks only the inner loop in the case of the nested loop.

    example:

    for(int i = 0; i<= 10; i++) {  

    System.out.println(i);  

    if(i==6) {  

    break;  

    }  

    }  

    continue statement:

    The continue statement doesn't break the loop, whereas, it skips the specific part of the loop and jumps to the next iteration of the loop immediately.

    example:

    for(int i = 0; i<= 10; i++) {  

    System.out.println(i);  

    if(i==6) {  

    break;  

    }  

    }  

    No comments:

    Post a Comment