Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    Difference Between Break and Continue Statements in java

    Java Programming Tutorials


    The keywords break and continue keywords are part of control structures in Java. Sometimes break and continue seem to do the same thing but there is a difference between them.

    The break keyword is used to breaks(stopping) a loop execution, which may be a for loop, while loop, do while or for each loop.

    The continue keyword is used to skip the particular recursion only in a loop execution, which may be a for loop, while loop, do while or for each loop.

    Example:

    class BreakAndContinue
    {
        public static void main(String args[])
        {
            // Illustrating break statement (execution stops when value of i becomes to 4.)
            System.out.println("Break Statement\n....................");
    
            for(int i=1;i<=5;i++)
            {
                if(i==4) break;
                System.out.println(i);
            }
    
            // Illustrating continue statement (execution skipped when value of i becomes to 1.)
            System.out.println("Continue Statement\n....................");
    
            for(int i=1;i<=5;i++)
            {
                if(i==1) continue;
                System.out.println(i);
            }
        }
    }

    Program Output:

    Break Statement
    ....................
    1
    2
    3
    
    Continue Statement
    ....................
    2
    3
    4
    5


    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.