java-控制语句

break:演示

class BreakDemo 
{
    public static void main(String[] args) 
    {
        /*
        break:使用范围:switch 循环语句。
        */
        /*
        for (int x=0; x<3 ;x++ )
        {
            if(x==1)
                break;
            System.out.println("x="+x);            
        }
        */
        outer:for (int x=0; x<3 ;x++ )
        {
            inner:for (int y=0; y<4 ;y++ )
            {
                System.out.println("x="+x);
                break outer;
            }
        }
    }
}

 continue:演示

class ContinueDemo 
{
    public static void main(String[] args) 
    {
        /*
        continue:只作用于循环结构。
        
        结束本次循环,继续下次循环。
        */
        for (int x=0; x<10 ;x++ )
        {
            if(x%2==0)
                continue;
            System.out.println("x="+x);
            
        }

        outer:for (int x=0; x<3 ;x++ )
        {
            inner:for (int y=0; y<4 ;y++ )
            {
                System.out.println("x="+x);
                continue outer;
            }
        }
        
    }
}

猜你喜欢

转载自www.cnblogs.com/zhxy0526/p/10767505.html