A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 18463730277 中级黑马   /  2015-5-5 23:26  /  250 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文


class BreakAndContinueDemo
{
        public static void main(String[] args)
        {
                //我写个例子,输出1-10
                for(int x=1; x<=10; x++)
                {
                        System.out.println(x);
                }
                System.out.println("*****");

                //用break
                for(int x=1; x<=10; x++)
                {
                        //break; 错误
                        System.out.println(x);
                        break;
                }
                System.out.println("*****");

                //用continue
                for(int x=1; x<=10; x++)
                {
                        //continue; 错误
                        //System.out.println(x);
                        //continue;
               
                        if(x%2==0)
                        {
                                //continue;
                                break;
                        }

                        System.out.println(x);
                }
        }
}


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马