Sunday 11 September 2011

Using break as a Goto satement in JAVA

/* Using break as a Goto satement:

Java doesnot have a goto statement, so we use break inted of Goto statement

*/

class Goto
{
public static void main(String args[])
{
boolean t=true;

first: {
   second: {
       third: {
           System.out.println("Before Break Statement");        
        if(t) break second; // break out of the second block
           System.out.println("This line won't execute");
              }
             System.out.println("This line won't execute");
           }
      System.out.println("This is after second block");
    }
  }
}

No comments: