0
Q:

how to break the statement using the if statement

// Java program to illustrate using return 
class Return 
{ 
    public static void main(String args[]) 
    { 
        boolean t = true; 
        System.out.println("Before the return."); 
      
        if (t) 
            return; 
  
        // Compiler will bypass every statement  
        // after return 
        System.out.println("This won't execute."); 
    } 
} 
0
// Java program to illustrate using break with goto 
class BreakLabelDemo 
{ 
    public static void main(String args[]) 
    { 
        boolean t = true; 
  
        // label first 
        first: 
        { 
            // Illegal statement here as label second is not 
            // introduced yet break second; 
            second: 
            { 
                third: 
                { 
                    // Before break 
                    System.out.println("Before the break statement"); 
  
                    // break will take the control out of 
                    // second label 
                    if (t) 
                        break second; 
                    System.out.println("This won't execute."); 
                } 
                System.out.println("This won't execute."); 
            } 
  
            // First block 
            System.out.println("This is after second block."); 
        } 
    } 
} 
0
// Java program to illustrate using 
// continue in an if statement 
class ContinueDemo 
{ 
    public static void main(String args[]) 
    { 
        for (int i = 0; i < 10; i++) 
        { 
            // If the number is even 
            // skip and continue 
            if (i%2 == 0) 
                continue; 
  
            // If number is odd, print it 
            System.out.print(i + " "); 
        } 
    } 
} 
0

New to Communities?

Join the community