Site hosted by Angelfire.com: Build your free website today!
 

Label

Because continue and break only work on the current loop, labels can be used to further control the loop. Labels can be placed at the beginning of a loop, and you can continue or break to the label. An example of how to use a label follows:

class Br {
    public static void main(String[] args) {
        int x = 0;
        int y = 0;
outer: 
        for (x = 0; x < 10; x++) {
inner: 
            System.out.println("outer loop: " + x);
            for (y =0; y < 10; y++) {
                if (x * 10 + y > 52) 
                    break outer; // break to outer loop
            }
        }
        System.out.println("x=" + x + " y=" + y);
    }
}