Java Break & Continue

Learn break and continue statements in Java with loops, examples, nested loops, and real use cases.

What is Break Statement?

break statement stops loop execution immediately.

for(int i=1; i<=5; i++){

    if(i == 3){

        break;

    }

    System.out.println(i);

}

Output

1
2

Continue Statement

continue skips current iteration.

for(int i=1; i<=5; i++){

    if(i == 3){

        continue;

    }

    System.out.println(i);

}

Output

1
2
4
5

Break in Switch

switch(day){

    case 1:
        break;

}

Nested Loop Example

for(int i=1; i<=3; i++){

    for(int j=1; j<=3; j++){

        if(j == 2){

            break;

        }

        System.out.println(j);

    }

}

Best Practices