Java-Label Break Statement (Exit Labelled Loop)

Label Break Statement (Exit Labelled Loop)

Label break statement is used exit from loops. Once you labeled a loop, you can use this label as the target of break statement. When compiler see break statement with label than compiler transfer execution to at end of labeled loop.

Progarm

Program Source

class Javaapp {

    public static void main(String[] args) {

        section :
        for(int i=0;i<5;i++)
        {
            System.out.println("Value of i = "+i);
            if(i==2)
            {
                break section;
            }
        }
    }
}

Leave a Comment